【发布时间】:2021-09-20 15:41:41
【问题描述】:
我一直在尝试在注册时设置我的用户显示名称。我在 stackoverflow 中找到的所有解决方案都建议使用 updateProfile()。但它已被弃用,flutter 文档说要改用 updateDisplayName。
我尝试过这样实现,
void donorSignUp() async {
try {
showLoading();
await auth
.createUserWithEmailAndPassword(
email: email.text.trim(), password: password.text.trim())
.then((result) {
String _userId = result.user!.uid;
_addDonorToFirestore(_userId);
_clearSignUpControllers();
result.user?.updateDisplayName(donorModel.value.name);
});
} catch (e) {
debugPrint(e.toString());
Get.snackbar('Sign Up Failed', 'Try again');
}
}
但是,当我尝试在 Drawer 中显示它时,调用 user?.displayName 它什么也没显示。我还检查了donorModel.value.name 包含一个字符串值,我知道它不为空。我该怎么办?
函数donorSignUp() 在提升按钮内调用,
child: ElevatedButton(
child: Text(
'Register',
style: buttonFontSansita,
),
onPressed: () {
if (authController
.signupFormKey.currentState!
.validate()) {
authController.donorSignUp();
}
},
【问题讨论】:
-
你能把它称为未来吗?
-
能否详细说明?
-
donorSignUp() 你从哪里调用它,请分享你调用donorSignUp() 的那些代码
-
我在提升按钮内调用函数,我已经在问题中更新了它。
-
您可以在注册完成后使用共享首选项进行存储,并在调用您的抽屉以显示名称时再次调用共享首选项。
标签: firebase flutter dart firebase-authentication