Reputation: 1736
In my Flutter project I have following code:
if(await model.login(loginMailTextController.text,
loginPasswordTextController.text)){
Navigator.of(context).pushReplacementNamed("/main");
}
This code calls this function in my model:
Future<bool> login(String mail, String password) async {
_auth.signInWithEmailAndPassword(email: mail, password: password);
return true; //Makes no sense, only for testing
}
Which works as expected and the navigator method is called, but if I add the await before the signInWithEmailAndPassword
method:
Future<bool> login(String mail, String password) async {
await _auth.signInWithEmailAndPassword(
email: mail, password: password);
return true; //Debugger won't stop there when a breakpoint is set
}
Then the expression in the if statement is false. Also when a breakpoint is set on the marked line, the debugger don't stop. Setting a breakpoint onto the signInWithEmailAndPassword
method works like charme.
Is this a bug or do I make a mistake?
Upvotes: 5
Views: 1553
Reputation: 657338
"if statement is false" looks like await _auth.signInWithEmailAndPassword(
throws and the exception is not reported or similar.
Try to wrap the code with try/catch
Upvotes: 4