firebase使用where获取一些数据

firebase使用where获取一些数据,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,这是我的firebase每个由不同用户添加的文档组我想获取基于userId的文档我在id变量中排序了该文档,这是我的代码条件不起作用,它获取我收集的所有文档 stream: FirebaseFirestore.instance .collection('glucose') .where('userId', isEqualTo: id) .snapshots(), builder

这是我的firebase每个由不同用户添加的文档组我想获取基于userId的文档我在id变量中排序了该文档,这是我的代码条件不起作用,它获取我收集的所有文档

stream: FirebaseFirestore.instance
                .collection('glucose')
                .where('userId', isEqualTo: id)
                .snapshots(),
            builder:
                (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
              if (snapshot.hasData) {
                for (int index = 0;
                    index < snapshot.data.docs.length;
                    index++) {
                  DocumentSnapshot documentSnapshot = snapshot.data.docs[index];
                  chartData.add(ChartData.fromMap(documentSnapshot.data()));
                }   
stream:FirebaseFirestore.instance
.收集(“葡萄糖”)
.where('userId',isEqualTo:id)
.snapshots(),
建设者:
(BuildContext上下文,异步快照){
if(snapshot.hasData){
对于(int指数=0;
索引

尝试下面的查询,让我知道它是否有效:)

此外,在这种情况下,您可能会得到
Map
,因此您可以使用
.Map((e)=>null).toList()
将它们放入列表中,并使用
列表视图
或适合您的方式呈现它们:)

StreamBuilder(
流:
FirebaseFirestore.instance.collection('glucose').snapshots(),
建设者:
(BuildContext上下文,异步快照){
if(snapshot.hasData){
返回列表视图(
子项:snapshot.data.docs.map(
(singleDoc){
if(snapshot.data.docs.contains(singleDoc['userID']))
回程卡(
孩子:ListTile(
标题:正文(
singleDoc['someFieldHere'],
),
),
);
},
).toList(),
);
}否则{
返回中心(
子对象:CircularProgressIndicator(),
);
}
},
),

文档id与用户id不相等,因此这将不起作用。它将自动检查是否有
docID
等于
userID
。其次,如果它们不相等,那么你为什么要传递它?有什么用?如果你愿意帮我提供你的twitter帐户来解释这个想法,请检查是否更新了答案我的社交手柄在我的个人资料中,你可以随时联系我:)请检查你的twitter,确认其他文档是否具有相同的用户ID或不同的用户ID