1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] ERROR IN Firebase OTP Auth Using Bloc in flutter

Discussão em 'Mobile' iniciado por Stack, Outubro 25, 2024 às 05:52.

  1. Stack

    Stack Membro Participativo

    This is bloc code

    void _verifyPhoneNumber(
    LoginInSubmittedEvent event, Emitter<SignInState> emit) async {
    String phone = "+91${event.phoneNumber}";
    try {
    emit(SignInLoadingState());
    await firebaseAuth.verifyPhoneNumber(
    phoneNumber: phone,
    verificationCompleted: (PhoneAuthCredential credential) async {
    emit(SignInCompletedState(credential));
    },
    verificationFailed: (FirebaseAuthException e) async {
    emit(SignInErrorState(e.toString()));
    },
    codeSent: (String verificationId, int? resendToken) async {
    emit(SignInValidateState(verificationId, resendToken));
    },
    codeAutoRetrievalTimeout: (String verificationId) async {
    emit(SignInTimeoutState(verificationId));
    },
    );
    } catch (e) {
    emit(SignInErrorState(e.toString()));
    }


    }

    Getting Updating State using Bloc here on button click calling the event add(LoginInSubmittedEvent() and checking all states here

    child: TextButton(
    onPressed: () {
    const phoneNumber = '3453453252';

    //BLOC TESST
    BlocProvider.of<SignInBloc>(context)
    .add(LoginInSubmittedEvent(
    phoneNumber));
    if (state is SignInInitialState) {
    debugPrint('Initial State');
    } else if (state
    is SignInLoadingState) {
    debugPrint('Loading State');
    } else if (state is SignInErrorState) {
    Text(state.errorMessage);
    } else if (state
    is SignInValidateState) {
    debugPrint('OTP SENT State');
    } else if (state
    is SignInTimeoutState) {
    debugPrint('TimeOut State');
    }
    },
    child: Text(
    'Get Otp',
    style:
    AppTextStyles.backNextBtnTextStyle,
    ),
    ),


    Getting ERROR Is

    **BAD** on<Event>((event, emit) { future.whenComplete(() => emit(...)); });: **GOOD** on<Event>((event, emit) async {
    await future.whenComplete(() => emit(...)); }); use emit.isDone after asynchronous operations before calling emit() to ensure the event handler has not completed.

    Continue reading...

Compartilhe esta Página