![](/img/trans.png)
[英]Getting all documents uids from firestore and add them to a list .flutter
[英]Unable to add all Firestore documents to a local variable in Flutter
我有一个名为cattle-feed
的 Firestore 集合。 它有7个文件。 我正在使用 StreamBuilder 通过快照获取这些文档并将它们添加到名为products
的列表中。 products
被初始化为一个空列表。
面临的问题:
我只能将cattle-feed
集合的前 4 个文档添加到列表变量products
中。
我的代码:
StreamBuilder(
stream: FirebaseFirestore.instance.collection('cattle-feed').snapshots(),
builder: (context, snapshot) {
if(snapshot.hasData){
products.clear();
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index2){
// products.clear();
products.add(Map.from(snapshot.data!.docs[index2].data()));
我的代码有什么问题,它只允许我复制 4 个 Firestore 文档而不是全部 7 个,解决方案是什么?
尝试更换:
products.add(Map.from(snapshot.data!.docs[index2].data()));
和:
products.add(snapshot.data!.docs[index2].data() as Map<String, dynamic>);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.