flutter中的火箱请求避免,然后阻止

发布于 2025-01-21 18:57:50 字数 926 浏览 2 评论 0原文

我正在尝试从Firebase中收到当前登录的用户的用户名,以在Appbar中显示名称。我目前正在使用FutureBuilder进行此操作,该方法将以下方法作为未来:

 _getUser() async {
        print("we are inside!!!");
        await FirebaseFirestore.instance
            .collection('users')
            .where("user_id", isEqualTo: FirebaseAuth.instance.currentUser!.uid)
            .snapshots()
            .first
            .then((QuerySnapshot querySnapshot) {
          querySnapshot.docs.forEach((doc) {
            this._userName = doc["user_name"];
            print("we found username: " + _userName);
          });
        });
        await Future.delayed(Duration(seconds: 1));
        print("i bims hier rein");
        return this._memoizer.runOnce(() async {
          return _userName;
        });
      }

到目前为止效果很好:我为新用户添加了某种教程(package:tutorial_coach_mark)。当在教程中登录的新用户出现并在教程开始后,应用程序启动,但是用户的名称并未通过上面显示的方法收到。

当用户是旧用户并且教程未显示时,将收到名称。

提前致谢!

I am trying to recieve the username of the currently logged in user from firebase, to show the name in the appbar. I am currently doing this with a FutureBuilder, which got the following method as future:

 _getUser() async {
        print("we are inside!!!");
        await FirebaseFirestore.instance
            .collection('users')
            .where("user_id", isEqualTo: FirebaseAuth.instance.currentUser!.uid)
            .snapshots()
            .first
            .then((QuerySnapshot querySnapshot) {
          querySnapshot.docs.forEach((doc) {
            this._userName = doc["user_name"];
            print("we found username: " + _userName);
          });
        });
        await Future.delayed(Duration(seconds: 1));
        print("i bims hier rein");
        return this._memoizer.runOnce(() async {
          return _userName;
        });
      }

That worked perfectly fine until now: I added some kind of tutorial for new users (package: tutorial_coach_mark). When a new user logged in the tutorial shows up and after the tutorial the app starts, but the name of the user isn't recieved by the method shown above.

When the user is a old user and the tutorial does not show, the name is recieved.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文