I have a try .. catch
block when loggin in or signing up with FirebaseAuth.instance
This is the code that I have.
try {
//... code here
} on PlatformException catch (err) {
var message = 'An error occured, please check your credentials.';
if (err.message != null) {
message = err.message!;
}
ScaffoldMessenger.of(ctx).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: Theme.of(ctx).errorColor,
),
);
// other codes here
} catch (err) {
print(err);
}
The problem now is that if I’m encountering an error like The email address is badly formatted.
or he email address is already in use by another account
, this is not going inside the on PlatformException catch (err)
block and its goin in the catch
block instead.
How can I make sure that the types of errors I mentioned above should be executed in the on PlatformException
block?
2
Answers
Alright! I have resolved it by using
on FirebaseAuthException
instead ofon PlatformException
. Hopefully this will help others who will be experiencing the same problem in the future.Try with this hope you’ll get the solution!
AuthExceptionHandler class for managing error message according error code.