【问题标题】:Updating FirebaseUser DisplayName (email auth) isn't updating instance CurrentUser更新 FirebaseUser DisplayName(电子邮件身份验证)不会更新实例 CurrentUser
【发布时间】:2018-11-18 15:14:12
【问题描述】:

这可能类似于: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;
  });
}

【问题讨论】:

  • 供参考,这似乎是相关的:github.com/flutter/flutter/issues/20390
  • 我已经使用上述方法创建了一个解决方法,在currentUser().reload() 之后使用Future.Delayed 3 秒,然后重新初始化FirebaseAuth.instance
  • 你能帮我看看你是怎么解决的吗?我正在实现类似的东西,用户在点击save 按钮时更新他们的名字。目前在我的onTap 方法上,我有这个代码:pastebin.com/gem16ZWU。如果我在那里遗漏任何东西,你能告诉我吗?让它发挥作用的下一步是什么?即成功保存名称并检索它?在这里感谢您的帮助。 @主题

标签: firebase dart firebase-authentication flutter


【解决方案1】:

对我有用

FirebaseAuth.instance.currentUser().then((val) {
      UserUpdateInfo updateUser = UserUpdateInfo();
      updateUser.displayName = myFullName;
      updateUser.photoUrl = picURL;
      val.updateProfile(updateUser);
    });

【讨论】:

  • 您的代码可以很好地更新信息,但即使在 FirebaseAuth.instance.currentUser().reload() 这是我的问题的核心之后,应用程序也无法立即使用它。
猜你喜欢
  • 2020-11-22
  • 1970-01-01
  • 2021-01-20
  • 2019-07-16
  • 2020-05-08
  • 2020-06-22
  • 2021-04-24
  • 2021-07-21
  • 2014-06-29
相关资源
最近更新 更多