Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To obtain the ids of documents in a list using Flutter Firestore, you can use the .documentID property of a Firestore document. Here's an example code snippet:

Firestore.instance
    .collection('myCollection')
    .getDocuments()
    .then((QuerySnapshot snapshot) {
  List<String> documentIds = [];
  snapshot.documents.forEach((DocumentSnapshot document) {
    documentIds.add(document.documentID);
  });
  print(documentIds); // prints a list of the document ids
});

In this code, we're using the getDocuments() method to retrieve all the documents in the collection called myCollection. Then, we're iterating over each document using a for-each loop and adding its documentID value to a list called documentIds. Finally, we're printing out the list of document ids.