注册Firebase颤振时更新displayName
我希望应用程序在用户注册时保存注册Firebase颤振时更新displayName,firebase,flutter,dart,firebase-authentication,Firebase,Flutter,Dart,Firebase Authentication,我希望应用程序在用户注册时保存displayName 我试过: Future<void> signUp() async { try { FirebaseUser user = (await FirebaseAuth.instance .createUserWithEmailAndPassword( email: email.text, password: password.text))
displayName
我试过:
Future<void> signUp() async {
try {
FirebaseUser user = (await FirebaseAuth.instance
.createUserWithEmailAndPassword(
email: email.text, password: password.text))
.user;
UserUpdateInfo userUpdateInfo = new UserUpdateInfo();
userUpdateInfo.displayName = name.text;
await user.reload();
showInSnackBar("User name ${user.displayName}");
try {
await user.sendEmailVerification();
showInSnackBar("Email verification sent");
} catch (e) {
print(e);
}
} catch (e) {
String errorCode = e.code;
print(e);
if (errorCode == "ERROR_EMAIL_ALREADY_IN_USE") {
showInSnackBar("This email is already in use");
} else {
showInSnackBar("Somthing went wrong! Try again later");
}
}
}
Future signUp()异步{
试一试{
FirebaseUser用户=(等待FirebaseAuth.instance
.createUserWithEmailAndPassword(
电子邮件:email.text,密码:password.text)
.用户;
UserUpdateInfo UserUpdateInfo=新的UserUpdateInfo();
userUpdateInfo.displayName=name.text;
等待user.reload();
showinsnakbar(“用户名${User.displayName}”);
试一试{
等待用户。sendEmailVerification();
showinsnakbar(“发送电子邮件验证”);
}捕获(e){
印刷品(e);
}
}捕获(e){
字符串errorCode=e.code;
印刷品(e);
if(errorCode==“ERROR\u EMAIL\u已在使用中”){
showinsnakbar(“此电子邮件已在使用”);
}否则{
showinsnakbar(“出现问题!请稍后再试”);
}
}
}
使用此方法,
SnakBar
为displayName
返回一个空值,设置userUpdateInfo.displayName=name。text
不足以实际更改用户帐户上的名称。为了实际更改帐户,您必须调用并传递该对象
await user.updateProfile(userUpdateInfo)