Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How can I get all documents name of a collection in Firestore

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

like image 772
Berkkan Avatar asked Nov 28 '22 21:11

Berkkan


1 Answers

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));
like image 143
Alex Adrianov Avatar answered Dec 04 '22 12:12

Alex Adrianov