please how can I get all the value of my IndividualTaxData
subcollection in Flutter.

- 421
- 5
- 10

- 61
- 6
-
2Please edit the question to show what you've tried that isn't working the way you expect. I suggest starting with the documentation. https://pub.dev/packages/cloud_firestore – Doug Stevenson May 05 '20 at 03:09
2 Answers
First, you must get the reference to the parent document:
DocumentReference parentRef = Firestore.intances.collection('TaxData').document(taxDataId);
You can do the previous part with a direct reference to the document (like the code above) or with a query. Later, you must get the reference of the subcollection and the document that you get the information:
DocumentReference subRef = parentRef.collection('IndividualTaxData').document(individualTaxId);
And finally, get the data:
DocumentSnapshot docSnap = await subRef.get();

- 421
- 5
- 10
-
Thank you very much, but what's the purpose of the parent reference I didn't see it being used anywhere in your code – nonso edu May 05 '20 at 13:20
-
the error was from my path... thank you very much, but I have to ask why use document reference instead of collection reference – nonso edu May 06 '20 at 19:25
For you to return a simple document, you can use the following code for it.
var document = await Firestore.instance.collection('IndividualTaxData').document('<document_name>');
document.get() => then(function(document) {
print(document('character'));
// you can print other fields from your document
}
With the above code, you will reference your collection IndividualTaxData
and then load it's data to a variable that you can print the values.
In case you want to retrieve all the documents from your collection, you can start using the below code.
final QuerySnapshot result = await Firestore.instance.collection('IndividualTaxData').getDocuments();
final List<DocumentSnapshot> documents = result.documents;
documents.forEach((data) => print(data));
// This print is just an example of it.
With this, you will load all your documents into a list that you iterate and print after - or that you can use with another method.
In addition to that, as future references, I would recommend you to check the following links as well.
- Query a single document from Firestore in Flutter (cloud_firestore Plugin)
- How to use Cloud Firestore with Flutter
Le me know if the information helped you!

- 4,199
- 1
- 10
- 22
-
-
-
thanks again, I will try this... just to be sure... will this work for subcollection – nonso edu May 06 '20 at 15:05
-
thank you very much I used the flutter cloud_firestore class, CollectionReference class to store my query I think it did most of the heavy lifting for me... – nonso edu May 06 '20 at 19:28
-
That's great @nonsoedu ! If you think my answer helped you, please consider accepting it or upvoting it. – gso_gabriel May 11 '20 at 09:45