我創建了 2 個不同的集合(用戶和關注)。
現在我想:
collection("list")根據他們的 id獲取存在于跟隨者中的檔案。在第一個集合中獲取用戶資料
currentUid = doc.id(對于第二個集合)。中顯示資料
ListTile。
第一次收藏
await FirebaseFirestore.instance.collection("users").doc(currentUid).set({"name":username,"photoUrl":url,"uid":currentUid});
第二集
await FirebaseFirestore.instance.collection("follow").doc(currentUid).collection("list").doc(otherId);
我用過這個,但它不能正常作業
body:StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection("follow")
.doc(user!.uid)
.collection("list")
.snapshots(),
builder: (context, snapshot1) {
if (!snapshot1.hasData) {
return Container();
} else {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection("users")
.where("uid",
isEqualTo:
snapshot1.data!.docs.map((e) => e.id).toList())
.snapshots(),
builder: (context, snapshot2) {
if (!snapshot2.hasData) {
return Container();
} else {
return ListView(
children: snapshot2.data!.docs.map((e) {
return ListTile(
leading: CircleAvatar(
backgroundImage: NetworkImage(e.get('url')),
radius: 30,
),
title: Text(e.get('username')),
);
}).toList(),
);
}
},
);
uj5u.com熱心網友回復:
您應該使用in 查詢而不是equal to查詢。
in 查詢回傳給定欄位與任何比較值匹配的檔案。
cloud_firestore 中in查詢的語法是這樣的:
.where(field, whereIn: listOfFields)
解決方案:
改變這個:
.where("uid", isEqualTo: snapshot1.data!.docs.map((e) => e.id).toList())
對此:
.where("uid", whereIn: snapshot1.data!.docs.map((e) => e.id).toList())
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/329010.html
標籤:安卓 火力基地 扑 镖 谷歌云firestore
