更新 FirebaseUser DisplayName(电子邮件身份验证)不会更新实例 CurrentUser

the*_*ene 5 dart firebase firebase-authentication flutter

这可能类似于:FirebaseUser's profile is not updated

但是,可以肯定的是,我对自己的 Flutter 技能没有信心。我正在尝试在 Firebase 中更新 DisplayName,然后将currentUser.displayName. updateProfile 似乎运行得很好,但即使在 reload() 调用之后 currentUser 也不会使用新的 displayName 进行更新。

我希望任何人都可以告诉我我做错了什么,或者将其归咎于 Firebase 中的错误。

我的代码:

Future _update(FirebaseUser user, String displayName) async {
  UserUpdateInfo _updateData= new UserUpdateInfo();
  _updateData.displayName = displayName;
  await user.updateProfile(_updateData);
  await user.reload();
  setState(() {
    _currentDisplayName = user.displayName;
  });
}
Run Code Online (Sandbox Code Playgroud)

小智 4

它对我有用

FirebaseAuth.instance.currentUser().then((val) {
      UserUpdateInfo updateUser = UserUpdateInfo();
      updateUser.displayName = myFullName;
      updateUser.photoUrl = picURL;
      val.updateProfile(updateUser);
    });
Run Code Online (Sandbox Code Playgroud)

  • 您的代码可以很好地更新信息,但即使在“FirebaseAuth.instance.currentUser().reload()”之后,应用程序也无法立即使用它,这是我问题的核心。 (3认同)