skip to Main Content

I’m building a flutter Android application and I’m using Firebase Authentication for managing the user.

Email Verify view

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


  1. Here the user can be null so you can use

    await user?.reload();
    
    Login or Signup to reply.
  2. Because Your user is get null when you reload your user.
    just remove this line

    await user.reload();
    

    because without this your code can work also.
    your error is resolved.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search