reloadCurrentUser method

Future<FirebaseUser> reloadCurrentUser (
  1. [EmissionPredicate predicate]
)

Reloads the current FirebaseUser, using an optional predicate to decide if the reloaded FirebaseUser should be emitted by onUserReloaded or not. If a predicate isn't provided the reloaded FirebaseUser will always be emitted.

The reloaded FirebaseUser will always be returned, independently of the predicate's result.

Example for getting updates only when FirebaseUser.isEmailVerified is true:

FirebaseUserReloader.onUserUpdated.listen((user) {
     print(user);
});

// Calling this will print the user, if its email has been verified.
await FirebaseUserReloader.reloadCurrentUser(FirebaseAuth.instance,
    (user) => user.isEmailVerified);

Implementation

static Future<FirebaseUser> reloadCurrentUser(
    [EmissionPredicate predicate]) async {
  FirebaseUser oldUser = await auth.currentUser();
  // we need to first reload to then get the updated data.
  await oldUser.reload();
  FirebaseUser newUser = await auth.currentUser();

  if (predicate == null || predicate(newUser)) {
    _userReloadedStreamController.add(newUser);
  }

  return newUser;
}