gpt4 book ai didi

flutter - Firebase电子邮件验证波动

转载 作者:行者123 更新时间:2023-12-03 04:35:18 26 4
gpt4 key购买 nike

我有这段代码可以注册:

      Future<String> signUp({String email, String password}) async {
try{
await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);

return "Signed up";
} on FirebaseAuthException catch(e){
print("no se puede crear");
return e.message;
}
}
我需要实现来自firebase的验证邮件,这已经被问了很多,研究时我想到了这个,不推荐使用某些代码,这对我来说很难找到指导:
    Future<String> signUp({String email, String password}) async {
FirebaseUser user = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
try {
await user.sendEmailVerification();
return user.uid;
} catch (e) {
print("An error occured while trying to send email verification");
print(e.message);
}
}
}
但是无法说明如何实现它,因为它抛出:

A value of type 'UserCredential' can't be assigned to a variable of type 'FirebaseUser'.

最佳答案

createUserWithEmailAndPassword不返回FirebaseUser对象。从链接的API文档中可以看到,它产生了一个UserCrediental对象。这就是错误消息试图告诉您的内容-您无法将UserCredential分配给FirebaseUser类型的变量。
如果要从UserCredential中获取FirebaseUser对象,则可以简单地使用其user属性。

UserCredential credential = await _firebaseAuth.createUserWithEmailAndPassword(email: email, password: password);
FirebaseUser user = credential.user;

关于flutter - Firebase电子邮件验证波动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64216342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com