【问题标题】:Changing display name takes too long. Flutter and FIrebase更改显示名称花费的时间太长。 Flutter 和 FIrebase
【发布时间】:2021-08-02 21:10:07
【问题描述】:

我正在尝试创建我的用户列表,并且显示名称在更新配置文件后需要进行一些更改,但到那时列表中的名称部分已经有一个空值。

final User user = (await
    _auth.createUserWithEmailAndPassword(
      email: emailR,
      password: passwordR,
    )
    ).user;
    user.updateProfile(displayName: usernameR);

    emailc.clear();
    passwordc.clear();
    usernamec.clear();

    DateTime now = DateTime.now();
    String dt = "${now.day.toString().padLeft(2,'0')}/${now.month.toString().padLeft(2,'0')}/${now.year.toString()} ${now.hour.toString()}:${now.minute.toString()}";

    FirebaseFirestore.instance.collection("users").doc(user.uid).set({
      "id": user.uid,
      "name": user.displayName,
      "email": user.email,
      "created_at": dt,
    });

我认为这是时间问题的原因是因为在我第一次注册时显示用户名的主页上,它会显示“嘿,null”,之后每次都会显示正确的用户名。

【问题讨论】:

    标签: firebase flutter google-cloud-firestore firebase-authentication


    【解决方案1】:

    updateProfile call 是一个异步操作,在该操作完成之前,user.displayName 不会被更新。幸运的是它返回一个Future,所以你可以在调用中使用await 等待它完成,就像你已经为createUserWithEmailAndPassword 所做的那样。

    所以:

    await user.updateProfile(displayName: usernameR);
    

    【讨论】:

      【解决方案2】:

      兄弟,你获取和发送数据的问题每件事都需要时间,所以为此你需要使用循环进度指示器,它需要 1 或 2 秒,兄弟首先在 firstore 中更改你的名称,然后从 firestore 中获取,因此避免这种使用当你的名字为空时,循环进度指标。希望你会喜欢我的建议

      【讨论】:

        猜你喜欢
        • 2015-06-07
        • 1970-01-01
        • 2014-02-16
        • 1970-01-01
        • 1970-01-01
        • 2014-10-01
        • 2013-08-07
        • 2011-12-06
        • 1970-01-01
        相关资源
        最近更新 更多