0

As you can see in the picture, collection 'Communities' got multiple documents inside of it which I managed to read all the data that is inside of it by applying this line of code:

 late QuerySnapshot Comms = await _firestore.collection('User').doc(User.userID).collection("Communities").get();

then applied this for the needed fields

 Text( Comms.docs[index].get("nameOfCommunity").toString(),),

but how can I get the ID of the collection that I got the data from?

enter image description here

  • You can get some idea [here](https://stackoverflow.com/questions/63302507/flutter-firebase-how-to-get-random-document). – gretal May 31 '22 at 00:58

1 Answers1

2

Firestore provides a property called id on the document snapshot, which you can access that in your case like this

comms.docs[index].id

Check this reference link

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Vishal Zaveri
  • 1,372
  • 2
  • 5
  • 12