My Idea:个 我想在Ffltter中使用Firebase Auth插件来注册用户. 但在他们访问应用程序之前,他们必须验证自己的邮箱地址. 因此,我在注册后将Firebase用户推送到验证屏幕.这只是一个加载屏幕,它告诉用户他必须验证他的邮箱.
But now:如果用户的邮箱经过验证或未验证,我如何继续收听并将他(如果是真的)发送到主屏幕?
我还是个初学者,我不知道是否必须使用Streams或可观察对象、While循环或setState()或其他什么来进行这样的布尔判断.我也不知道如何设置解决方案.
这是我注册用户的基本代码:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'dart:async';
class AuthService {
final FirebaseAuth _auth = FirebaseAuth.instance;
final Firestore _db = Firestore.instance;
Future<FirebaseUser> get getUser => _auth.currentUser();
Stream<FirebaseUser> get user => _auth.onAuthStateChanged;
Future<FirebaseUser> edubslogin(String email, String password) async {
try {
final FirebaseUser user = await _auth.createUserWithEmailAndPassword(
email: email,
password: password,
);
await user.sendEmailVerification();
//email verification somewhere here
updateUserData(user);
return user;
} catch (error) {
print(error);
return null;
}
}
我试过这个:
if (user.isEmailVerified == true) {
//go to Homescreen
return true;
} else {
//show verification screen(loading spinner)
return false;
}
但我得不到isEmailVerified
的布尔值true
.
我该怎么做?