我已经实现了以下代码.问题是,我需要知道用户帐户是否已创建,以便将用户转发到主屏幕.但是,由于我返回的是Fluttertoast(向用户显示错误消息),所以不能返回NULL.所以我想判断返回值是否为Fluttertoast.我怎么能做到这一点?或者,有没有更好的方法来实现这一点?
Future registerWithEmailAndPassword(
{required String email,
required String password,
required String userName,
required String gender}) async {
try {
UserCredential result = await _auth.createUserWithEmailAndPassword(
email: email, password: password);
User? user = result.user;
// create a new document for the user with the uid
await DatabaseService(uid: user!.uid)
.updateUserData(gender: gender, userMail: email, userName: userName);
return user;
} catch (error) {
return Fluttertoast.showToast(
msg: error.toString(),
gravity: ToastGravity.TOP,
backgroundColor: Colors.black,
textColor: Colors.white);
}
}
基本上,然后我想实现一条if语句来判断是否创建了用户帐户(然后返回flttertoast).类似于:
if (result == FToast()) {
print("user not created");
}