I’m new to flutter .So I was wondering if there is anyway that I can show the firebase auth error codes as the Errortext in textfield ?
I am able to print the exception from firebase_auth but dont know how to give it as the errortext .
try {
final newuser = await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: email ?? 'error',
password: password ?? 'error',
);
if (newuser != null) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProfileDetail()),
);
}
} catch (e) {
print(e);
}
},
this is the textfield
TextField(
onChanged: (value) {
username = value;
},
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Username',
// errorText:
),
),
3
Answers
You can use "showsnackBar"
First declare a variable to hold errorText;
Then extract the error like this,
You get common error codes from this link,
https://pub.dev/documentation/firebase_auth/latest/firebase_auth/FirebaseAuth-class.html
Use on
FirebaseAuthException
catch
like this.