I’m building a flutter Android application and I’m using Firebase Authentication for managing the user.
See the above email verify view.
I’m trying to refresh the details of my user. Whether the user is verified or not on pressing the continue button. But I’m getting the following errors:
I’m getting the below message for await user.reload();
The method ‘reload’ can’t be unconditionally invoked because the receiver can be ‘null’.
I’m getting the below message for user = await AuthService.firebase().currentUser();
The function can’t be unconditionally invoked because it can be ‘null’.
My code for OnPressed :
onPressed: () async {
var user = AuthService.firebase().currentUser;
await user.reload();
user = await AuthService.firebase().currentUser();
if (user?.isEmailVerified ?? false) {
// user's email is verified
Navigator.of(context).pushNamedAndRemoveUntil(
passwordsRoute,
(route) => false,
);
} else {
// user's email is NOT verified
Navigator.of(context).pushNamedAndRemoveUntil(
verifyEmailRoute,
(route) => false,
);
}
},
2
Answers
Here the user can be null so you can use
Because Your user is get null when you reload your user.
just remove this line
because without this your code can work also.
your error is resolved.