Flutter:如何在Firestore中获取集合的所有文档名称 [英] Flutter: How can I get all documents name of a collection in Firestore
本文介绍了Flutter:如何在Firestore中获取集合的所有文档名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在使用Firestore在Flutter中制作一个应用程序,我将遍历集合中的所有文档,并且想要获得文档名称(id)和文档字段,并对此进行处理.我已经建立了一个显示数据的列表视图,但是对此我无能为力,例如,将其添加到列表或其他内容中. 谢谢
I make an app in Flutter with Firestore now I would go through all documents in a collection and I want to get the document name (id) and the field of the documents and do something with that. I have already make a listview where the data is displayed but I can't do something with that, for example, add it to a list or something. Thanks
推荐答案
您可以通过获取以下文档列表来做到这一点:
You can do that by getting list of documents like:
final QuerySnapshot result =
await Firestore.instance.collection('myCollection').getDocuments();
final List<DocumentSnapshot> documents = result.documents;
然后您可以遍历此列表并获取数据:
And after that you can iterate this list and get data:
documents.forEach((data) => print(data));
这篇关于Flutter:如何在Firestore中获取集合的所有文档名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文