I want to sum the field (total income in January) of all document under the collection name ("januaryi").I tried a function that is not working. Is there any way to call function and show summation in bottom navigation bar.
Flutter Firebase:
Function:
class _JanuaryState extends State<January>{
totalmoney() async {
int total = 0;
var snapshot =
await Firestore.instance.collection("Januaryi").getDocuments();
if (snapshot == null){
return 0;
}
snapshot.documents.foreach((doc) {
total = total + int.parse(doc.data['income']);
});
return total;
}
}
Bottom Navigation Bar:
bottomNavigationBar: Container(
child: ListTile(
title: Text('Total'),
subtitle: Text("${totalmoney()}"),
)),
);
Showing error in total income: