【发布时间】:2020-06-14 08:24:22
【问题描述】:
我正在尝试从特定集合 users 中检索数据,如下面的代码所示,但是当我查询此集合中的用户时,列表视图不显示。换句话说,它只显示一个 CircularProgressIndicator() 表示没有数据可以找到。在我注释掉 where 查询的那一刻,listview 完美呈现。
backgroundColor: MyApp.backgroundColor,
body: StreamBuilder<QuerySnapshot>(
stream: _firestore
.collection('users')
// .where("chapter", isEqualTo: chapter)
.orderBy('count', descending: true)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Center(child: CircularProgressIndicator());
return ListView.builder(
itemExtent: 80.0,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) =>
_buildListItem(context, snapshot.data.documents[index]),
);
},
),
);
我尝试将 Nested StreamBuilders 和 FutureBuilder 与 Streambuilder 结合使用,但这些解决方案都不起作用。对于这样一个关键特性,必须有一个简单的解决方案。
请告诉我如何同时查询和使用 StreamBuilder。
【问题讨论】:
-
您是否在任何地方检查流的错误?如果没有,您应该这样做,因为您的查询可能会失败,并且错误会为您提供更多详细信息。
-
嗨,我发现了问题!我用 StreamBuilder 包裹了一个 FutureBuilder 并且成功了!
-
很高兴听到您发现了问题。您想发布您的工作代码和更改的解释作为答案吗?这样人们就可以看到您是如何解决问题的,并且随着时间的推移,您可能会赢得一些声誉。
-
没问题!现在添加
标签: listview flutter google-cloud-firestore querying stream-builder