Reputation: 17
I just want to make a verify screen and it will close when any user clicks the submitted verify link by Firebase. Should I add a future function for that?
if (!user.emailVerified){
user.sendEmailVerification();
Navigator.push(context,MaterialPageRoute(builder: (context) => VerifyScreen(),),);
}
What should I add to this code?
Upvotes: 0
Views: 82
Reputation: 8597
There are several ways to go about, and it depends on the behavior you want to have. If I understand you correctly, I would probably create a Cubit that subscribes to userChanges(), and on the VerifyScreen() page have a BlocListener that redirects the user away from that screen when the user has verified the email via the link.
Part in Cubit:
FirebaseAuth.instance.userChanges().listen((user) {
if (user.emailVerified) {
emit(UserEmailVerificationState.verified());
}
});
Part in VerifyScreen():
BlocListener<UserEmailVerificationCubit, UserEmailVerificationState>(
listener: (context, state) {
state.maybeMap(
verified: (_) {
ExtendedNavigator.of(context).replace(Routes.secretPage);
},
orElse: () {});
},
),
Upvotes: 1