firebase - 注册Firebase Flutter时更新displayName

标签 firebase flutter dart firebase-authentication

我希望应用程序在用户注册时保存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");
      }
    }
  }

使用此方法,SnakBardisplayName返回null

最佳答案

设置userUpdateInfo.displayName = name.text不足以实际更改用户帐户上的名称。您必须调用updateProfile()并将其传递给UserUpdateInfo对象才能实际更改帐户。

await user.updateProfile(userUpdateInfo)

关于firebase - 注册Firebase Flutter时更新displayName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62473424/

相关文章:

firebase - 从Firebase Firestore数据库集合中提取大量(大约300个)文档

android - Flutter : No valid Android SDK platforms found in/usr/lib/android-sdk/platforms. 目录为空

firebase - 如何从自定义域提供 firebase 功能?

flutter - 在 get_it Flutter 中注册依赖的异步服务定位器

ios - 有没有办法安排对 firebase 数据库的编辑?

flutter - 如何在Flutter中将2行文本与1行文本对齐

dart - flutter : Bad state: Stream has already been listened to

flutter - 如何将工厂方法包含到抽象类中?

firebase - 如何使用 Firebase 随机匹配用户

javascript - Web Firebase Cloud Messaging - 如何从客户端订阅主题?