[英]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.