Firebase 如何获取一个流值,然后使用Flatter with firestore调用另一个基于先前值的流
我试图从firestore流中获取我跟踪的用户的ID,然后用我的跟踪帖子和之前的ID调用另一个流 我不知道这是否是构建它的正确方法,如果是的话,如何用flutter实现它。。第一次调用我一直在尝试streamBuilder,但我不知道如何使用ID列表进行第二次流调用 我用来获取以下ID的函数Firebase 如何获取一个流值,然后使用Flatter with firestore调用另一个基于先前值的流,firebase,dart,flutter,google-cloud-firestore,Firebase,Dart,Flutter,Google Cloud Firestore,我试图从firestore流中获取我跟踪的用户的ID,然后用我的跟踪帖子和之前的ID调用另一个流 我不知道这是否是构建它的正确方法,如果是的话,如何用flutter实现它。。第一次调用我一直在尝试streamBuilder,但我不知道如何使用ID列表进行第二次流调用 我用来获取以下ID的函数 Stream<QuerySnapshot> followingUsersContent(String uid){ return _firestore.collection("following"
Stream<QuerySnapshot> followingUsersContent(String uid){
return _firestore.collection("following").document(uid).collection("userFollowing").snapshots();
}
并从这里存储:
List getFollowingsUidToList(List<DocumentSnapshot> docList){
if (docList != null){
List<UserFollowing> followingUidsList = [];
docList.forEach((document){
String uid = document.data["uid"];
UserFollowing userPost = UserFollowing(uid);
followingUidsList.add(userPost);
});
return followingUidsList;
}
}
List getfollowersuidtolist(List docList){
if(docList!=null){
以下列表UIDSList=[];
docList.forEach((文件){
字符串uid=document.data[“uid”];
UserFollowing userPost=UserFollowing(uid);
以下UIDSList.add(userPost);
});
返回UIDSList;
}
}
我现在只剩下与userFollowing.uid通信一个新流
我怎么做?谢谢。我想你可以使用嵌套的
StreamBuilders
你可以看到@ciplionat我的流函数有一个标识符,需要是用户id。这就是我获取id的模型。。它们是从第一个流List userInfoList=userscontetbloc.getfollowsuidtolist(docs)中检索到的
现在我需要执行用户信息列表[0]。uid
或是否有其他方法执行此操作。
postWidget(){
return Container(
child: StreamBuilder<QuerySnapshot>(
stream: usersContentProvider.followingUsersContent(profileId),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if (!snapshot.hasData) {
return Text("There's no data");
}
if (snapshot.hasData) {
List<DocumentSnapshot> docs = snapshot.data.documents;
List<UserFollowing> userInfoList = usersContentProvider.getFollowingsUidToList(docs);
return testUserID(userInfoList);
}
},
),
);
}
Widget testUserID(List<UserFollowing> userInfoList){
return Container(
child: Expanded(
child: ListView.builder(
itemCount: userInfoList.length,
itemBuilder: (BuildContext context, i){
return Text(userInfoList[i].uid ?? "There's no data", style: TextStyle(color: Colors.red),);
}
),
),
);
}
class UserFollowing{
final String _uid;
UserFollowing(this._uid);
String get uid => _uid;
}
List getFollowingsUidToList(List<DocumentSnapshot> docList){
if (docList != null){
List<UserFollowing> followingUidsList = [];
docList.forEach((document){
String uid = document.data["uid"];
UserFollowing userPost = UserFollowing(uid);
followingUidsList.add(userPost);
});
return followingUidsList;
}
}