Hello Flutter newbie here! I have setup the login and error checking part.
I want to do some checking on the fields, but I realize if the user does the following behavior, my code for error checking won't work:
- enter some text in email textfield
- enter some text in password textfield
- backspace delete the text in email textfield
- hit the flat button to submit
the code will pass the if checking and go ahead to sign in... but I thought since the email textfield is empty by the time I hit the button, it should still follow the if checking?
thanks in advance!
FlatButton(
onPressed: () async {
if (password == null && email == null) {
print('empty sign in info');
setState(() {
alertText = 'You have not entered your login info!';
});
} else if (password == null) {
setState(() {
alertText = 'Password cannot be blank!';
});
} else if (email == null) {
setState(() {
alertText = 'Email cannot be blank!';
});
} else {
setState(() {
showSpinner = true;
});
try {
final newUser = await _auth.signInWithEmailAndPassword(
email: email, password: password);
if (newUser != null) {
Navigator.pushNamed(context, ViewScreen.id);
}
} catch (e) {
print(e);
}
}
},
Aucun commentaire:
Enregistrer un commentaire