微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Flutter 应用程序中使用 async await inisde streamBuilder 或解决我在 StreamBuilder 中的未来?

如何解决如何在 Flutter 应用程序中使用 async await inisde streamBuilder 或解决我在 StreamBuilder 中的未来?

   child: Column(children: [
                StreamBuilder(
                    stream: firestore
                        .collection("messages")
                        .where("users",arrayContains: myid)
                        .snapshots(),builder: (context,snapshot) {
                      if (snapshot.hasData) {
                        List<Widget> children = [];
                        String whoseText;
                        String friendProfilePicUrl;
                        String lastmessage;
                        String friendId;
                        List<dynamic> userIds;
                        snapshot.data.docs.forEach((doc) {
                          if (doc.data()['idFrom'] == myid) {
                            whoseText = "You:";
                          } else {
                            return "";
                          }
                          userIds = doc.data()['users'];
                          userIds.remove(myid);
                          friendId = userIds[0];
                         
              METHODS I TRIED            
                           1.   ChatsController.getFriendProfilePic(friendId)
                              .then((value) => friendProfilePicUrl = value);

                           2.friendProfilePicUrl= await 
                        ChatsController.getFriendProfilePic(friendId);
                          lastmessage = doc.data()['lastMessage'];
                         
                          children.add(ChatsBuilder(
                            friendProfilePic: friendProfilePicUrl,whoseText: whoseText,lastMessage: lastmessage,));
                          print("the lists of idgets are $children");
                        });
                        print("which coms firesr $children");
                        print("frienfnfnfn $friendProfilePicUrl");
                        return Container(
                            child: Column(
                          children: children,));
                      } else {
                        return Text(
                          "no dtata",style: TextStyle(
                            color: Colors.black,fontSize: 20,),);
                      }

在 StreamBuilder 中使用 async await 没有构建任何东西,当我在方法上使用 .then 时......它说分配的 url 为空......我得到了朋友用户 ID 和他的个人资料信息来自“消息”集合流,因此不能在 initState 中使用它来获取这些值....我如何使用 async await 或如何在 streambuilder 中解决 future 问题?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。