I have a
Querysnapshot snapshot
I can supply an index and access the fields of the document perfectly like:
snapshot.data!.docs[index]
However, I want to access the field of document ‘thisParticularDocument’ which is the id (name) of the document in Cloud Firestore.
I want to use
snapshot.data!.docs[thisParticularDocument]
but that doesn’t work because you can only supply an index to docs.
I want a solution that preferably involves no async await.
2
Answers
when you a get a
QuerySnapshot
then you get all all documents of it including references and data.so you can get a specific document as you say like this:
and you can get the data of document like this:
then you can get the specific field inside of it like this:
that’s it the value of that field will be returned fine if it exists.
you can get the data of a document with a specific id without making a new async request by finding it like this:
this will get you the specific document from the
QuerySnapshot
.