-2

enter image description here

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

Chris Chávez
  • 421
  • 5
  • 10
nonso edu
  • 61
  • 6
  • 2
    Please 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 Answers2

0

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();
Chris Chávez
  • 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
0

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.

Le me know if the information helped you!

gso_gabriel
  • 4,199
  • 1
  • 10
  • 22