I have also recently faced this error and, I have found out that the .catchError()
callback wasn't being called in the debug mode (which is when you click the Run->Start Debugging
button in VSCode).
However, when you type in flutter run -d , then, the .catchError()
method gets called back as it is not in debug mode.
To get your preferred simulator's code paste this line of code in the terminal:
instruments -s devices
If that doesn't work, you can also try pasting this:
xcrun simctl list
The .catchError()
method will get called unlike before and the code inside that will get executed as expected!
Additionally, the app won't crash anymore with a PlatformException()
and instead you will get a log like this one:
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'uid' was called on null.
Receiver: null
I have been facing this problem in Google Sign In too, in which the .catchError()
was not being called!
In conclusion, if you have some error with handling errors in Firebase Authentication, you should first try to first run in through the terminal. Thanks, and I hope this helps!
This is a known issue.
Follow https://github.com/flutter/flutter/issues/18312
You can do trick by use Future Object
by example i want to use PhoneAuth and check Code write by user is true or not so the problem is cant catch the the exception come after user put wrong code
try this code first declare the async method like this
Future<FirebaseUser> _signInWithCode(String code) async {
AuthCredential phoneAuthCredential = PhoneAuthProvider.getCredential(
verificationId: verificationID, smsCode: code);
try {
AuthResult result = await mAuth.signInWithCredential(phoneAuthCredential);
FirebaseUser currentUser = await mAuth.currentUser();
if (currentUser != null && result.user.uid == currentUser.uid) {
return currentUser;
} else {
return null;
}
} on PlatformException catch (exp) {}
return null;
}
so if exp thrown the value come is null
and some where in my code after user submit code use this code
FirebaseUser user = await _signInWithCode(code);
if (user != null)
debugPrint("true input code");
else {
debugPrint("WRONNNG input code");
setState(() {
isValidCode = false;
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.