Flutter: How to listen to the FirebaseUser is Email verified boolean?

后端 未结 8 744
走了就别回头了
走了就别回头了 2021-01-01 20:38

My Idea: I want to use the Firebase Auth Plugin in Flutter to register the users. But before they can access the App, they have to verify their Email addres

8条回答
  •  清歌不尽
    2021-01-01 21:24

    Well I created a stream to handle this. Not so elegant but works. Use a StreamProvider.value() to handle events.

      Stream checkUserVerified() async* {
        bool verified = false;
        yield userVerificationStatus(status: Status.LOADING); 
        while (!verified) {
          await Future.delayed(Duration(seconds: 5));
          FirebaseUser user = await _auth.currentUser();
          if(user!=null)await user.reload();
          if (user == null) {
            yield userVerificationStatus(status: Status.NULL);
          } else {
            print("isemailverified ${user.isEmailVerified}");
            await user.reload();
            verified = user.isEmailVerified;
            if(verified)
            yield userVerificationStatus(status: Status.VERIFIED);
            else
            yield userVerificationStatus(status: Status.NOT_VERIFIED);
          }
        }
      }
    

提交回复
热议问题