我在Firestore,已订阅和列表中有2个收藏集。我想首先从第一个集合(已订阅)中过滤文档,以仅获取用户已订阅的文档,所以类似
FirebaseFirestore.instance.collection("subscribed").where("userId", isEqualTo: currentUser.uid).where("subscribed", isEqualTo: true).snapshots();
现在,一旦我从快照中获得了documentID,我想使用这些ID遍历那些特定列表并显示它们
我尝试过的是
StreamBuilder(
stream: getSharedListsStreamSnapshot(context),
builder: (context, snapshot) {
if (!snapshot.hasData)
return SpinKitDoubleBounce(color: Colors.black);
else
return new ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.docs.lenght,
itemBuilder: (BuildContext context, int index) =>
buildHomeViewCard2(context, snapshot.data.docs[index]));
}),
Stream<QuerySnapshot> getSharedListsStreamSnapshot(
BuildContext context) async* {
final uid = await Provider.of(context).auth.getCurrentUID();
await FirebaseFirestore.instance
.collection("subscribed")
.where("userId", isEqualTo: uid)
.where("subscribed", isEqualTo: true)
.get()
.then((val) {
FirebaseFirestore.instance
.collection("subscribed")
.where("userId", isEqualTo: uid)
.where("subscribed", isEqualTo: true)
.get()
.then((event) {
event.docs.forEach((element) {
FirebaseFirestore.instance
.collection("lists")
.where("id", isEqualTo: element['listId'])
.snapshots();
print(element['listId']);
});
});
});
Widget buildHomeViewCard2(
BuildContext context, DocumentSnapshot documentSnapshot) {
final lists = Lists.fromSnapshot(documentSnapshot);
final listIcon = lists.iconForList();
return Container(
child: InkWell(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: ListTile(
leading: (listIcon.containsKey(lists.icon))
? listIcon[lists.icon]
: listIcon["list"],
title: Text(
lists.name,
style: new TextStyle(fontSize: 20.0),
),
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TasksView(
lists: list,
),
));
},
),
);
}
}
它会打印元素['listId'],但不会在ui上显示任何列表。
感谢您的帮助 谢谢