首页 > 解决方案 > 用电话号码颤动登录

问题描述

我有一个问题,我无法解决。

在此处输入图像描述 在此处输入图像描述

在我点击验证按钮(第二张图片)后,它会返回第一张照片,仅此而已,就像 navigator.pop() 函数一样。

我有提供使用电话号码登录的功能,在这里:

Future<void> signInWithTelephoneNumber({String phoneNumber}) async {
    emit(state.copyWith(phoneNumber: phoneNumber,isInProgress: true, errorMessage: ""));

    await FirebaseAuth.instance.verifyPhoneNumber(
      phoneNumber: "+9$phoneNumber",
      timeout: const Duration(seconds: 30),
      verificationCompleted: (PhoneAuthCredential credential) async {
        await FirebaseAuth.instance.signInWithCredential(credential);
        print("Successsssssssssssssssssss");
      },
      verificationFailed: (FirebaseAuthException e) {
        if (e.code == 'invalid-phone-number') {
          print('The provided phone number is not valid.');
          emit(state.copyWith(errorMessage: "The provided phone number is not valid."));
        }
      },
      codeSent: (String verificationId, int resendToken) async {
        String smsCode = '123456';

        PhoneAuthCredential credential = PhoneAuthProvider.credential(
            verificationId: verificationId, smsCode: smsCode);

        await FirebaseAuth.instance.signInWithCredential(credential);
      },
      codeAutoRetrievalTimeout: (String verificationId) {},
    );

    emit(state.copyWith(phoneNumber: "",isInProgress: false, errorMessage: ""));
  }

当我单击登录按钮时,它会进入验证页面(chapcta 页面),在我验证图像后,它会出现此错误:

 Notifying id token listeners about user ( RID5Hq65CCcj1hXgyvVosA6QKbo1 ).
D/FirebaseAuth( 2708): Notifying auth state listeners about user ( RID5Hq65CCcj1hXgyvVosA6QKbo1 ).
E/flutter ( 2708): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value

我该怎么办 ?我怎么解决这个问题 ?我使用此链接作为来源:https ://firebase.flutter.dev/docs/auth/phone/

标签: flutterauthenticationdart

解决方案


我使用了 showDialog 并为短信代码提供输入。谢谢


推荐阅读