问题描述
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 (将#修改为@)