简体   繁体   中英

I am new in flutter firebase. I want to print total value of the field named amount of each firebase document

There is a field named Amount inside the document under a collection called Use of Fund. Now I want to add the value of the field named amount of each document enter image description here

First Step: Get the documents from the collection:

final result = await FirebaseFirestore.instance.collection('Use of Fund').get();

Second Step: Define a variable to hold the result and start it with 0:

double totalAmount = 0;

Third Step: Loop on the docs inside the result and add the amount of each doc :

for (var doc in result.docs){
    totalAmount += doc['amount'];
}

That's It!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM