简体   繁体   English

未处理的异常:[firebase_auth/unknown] null:使用颤振/firebase 进行电话身份验证时出错

[英]Unhandled Exception: [firebase_auth/unknown] null: Error in Phone Authentication using flutter/firebase

I have used this link as tutorial: https://firebase.flutter.dev/docs/auth/phone/ But somehow, as I press the button I get this error:我已将此链接用作教程: https://firebase.flutter.dev/docs/auth/phone/但不知何故,当我按下按钮时,我收到此错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: [firebase_auth/unknown] null
E/flutter ( 6765): #0      MethodChannelFirebaseAuth.verifyPhoneNumber (package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart:583:7)
E/flutter ( 6765): <asynchronous suspension>
E/flutter ( 6765): #1      _OTPScreenState._verifyMyPhoneNumber (package:food_delivery_app/UIForAllCategory/PhoneAuth/OTPScreen.dart:41:5)
E/flutter ( 6765): <asynchronous suspension>
E/flutter ( 6765): 
D/ViewRootImpl[Toast]( 6765): hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false

I have enabled phone authentication at Firebase and as well redownloaded the GoogleServices file but facing this error consistently.我在 Firebase 启用了电话身份验证,并重新下载了 GoogleServices 文件,但始终面临此错误。 This is the first function that runs on the press of button:这是第一个在按下按钮时运行的 function:

  _verifyMyPhoneNumber() async {
    //This handler will only be called on Android devices which support automatic SMS code resolution.
    await FirebaseAuth.instance.verifyPhoneNumber(
        phoneNumber: '+92${this.widget.phoneNumber}',
        verificationCompleted: (PhoneAuthCredential credential) async {
          await FirebaseAuth.instance
              .signInWithCredential(credential)
              .then((value) async {
            if (value.user != null) {
              //Change state and move to next Screen
              setState(() {
                this.widget.inProgress=false;
              });
              String myNumber=this.widget.phoneNumber;
              debugPrint("My number= $myNumber");
              prefs.setString("phone", "0$myNumber");

              //Getting values from preferences
              String number= prefs.getString("phone");
              String email=  prefs.getString("email");
              String username=  prefs.getString("username");
              String uid= prefs.getString("Gid");
              debugPrint("Details: $number, $email, $username,$uid");
              Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) => EnteryPoint()),
              );
            }
          });
        },


        //In case, if Some error occured at Firebase then
        verificationFailed: (FirebaseAuthException e) {

          //Change state and Go back with a prompt
          setState(() {
            this.widget.inProgress=false;
          });
          Fluttertoast.showToast(
              msg: "Error: $e",
              toastLength: Toast.LENGTH_SHORT,
              gravity: ToastGravity.CENTER,
              timeInSecForIosWeb: 2,
              backgroundColor: Colors.black87,
              textColor: Colors.white,
              fontSize: 12.0);
          Navigator.of(context).pop(); //Go back to previious screen
        },


        codeSent: (String verficationID, int resendToken) {
          debugPrint("Code is sent from Server, Soon you will recieve it");
          //Change state and Let user to enter the code when received
          setState(() {
            this.widget.inProgress=false;
          });
          Fluttertoast.showToast(
              msg: "Please wait, You will soon receive the code!",
              toastLength: Toast.LENGTH_SHORT,
              gravity: ToastGravity.CENTER,
              timeInSecForIosWeb: 2,
              backgroundColor: Colors.black87,
              textColor: Colors.white,
              fontSize: 12.0);
          setState(() {
            _verificationCode = verficationID;
          });
        },
        codeAutoRetrievalTimeout: (String verificationID) {
          debugPrint("This device has not automatically resolved an SMS message within a certain Timeframe");
          setState(() {
            _verificationCode = verificationID;
          });
        },
        timeout: Duration(seconds: 60));
  }

Help please!请帮忙!

Check if you do have an instance of firebaseapp at the start of the program (main function).检查您是否在程序开始时有一个 firebaseapp 实例(主函数)。 Instance is created using await Firebase.initializeApp();使用 await Firebase.initializeApp() 创建实例;

Your exception is the "instance of firebase_auth is null" and Firebase Auth doesn't work without firebaseapp.您的例外是“firebase_auth 的实例为空”并且 Firebase Auth 在没有 firebaseapp 的情况下不起作用。 Unhandled Exception: [firebase_auth/unknown] null未处理的异常:[firebase_auth/unknown] null

FirebaseAuth auth=FirebaseAuth.instance;
auth.userChanges();
auth.instance.verifyPhoneNumber(
//code`enter code here`
);

If you are trying to multiple login from one device如果您尝试从一台设备进行多次登录

Firebase have auth attempt limit. Firebase 有授权尝试限制。 Try again after day.隔天再试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 firebase 中注册用户(firebase_auth/unknown: null) - Can't register user in firebase (firebase_auth/unknown: null) Flutter&Firebase-与firebase_auth一起使用firebase_storage - Flutter & Firebase - using firebase_storage along with firebase_auth 未处理的异常:[firebase_auth/invalid-verification-id] 用于创建电话身份验证凭据的验证 ID 无效 - Unhandled Exception: [firebase_auth/invalid-verification-id] The verification ID used to create the phone auth credential is invalid flutter 中的 firebase_auth/无效电话号码? - firebase_auth/invalid-phone-number in flutter? 发生异常。 FirebaseAuthException([firebase_auth/未知] - Exception has occurred. FirebaseAuthException ([firebase_auth/unknown] firebase 电话号码身份验证不起作用未处理的异常:PlatformException(错误,空引用,空) - firebase phone number authentication is not working Unhandled Exception: PlatformException(error, null reference, null) 应用发布后的 firebase_auth/unknown 错误 - firebase_auth/unknown error after app release Flutter/Firebase_Auth:构建 function 返回 null - Flutter/Firebase_Auth: a build function returned null firebase_auth/too-many-requests Firebase 电话验证抖动 - firebase_auth/too-many-requests Firebase Phone Auth flutter 如何使用 firebase_auth 包修复 flutter 应用程序中的 FirebaseAuth.instance.currentUser()? 它总是返回 null - How to fix FirebaseAuth.instance.currentUser() in flutter app using firebase_auth package? It is always returning null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM