I want to sum two different firebase collection field values in my flutter app. That's why I write two functions. I can sum one collection field value but two collection field value sum in a single text widget is not working or I am not understanding how to do this..
Scaffold(
body: SafeArea(
child: Container(
child: StreamBuilder<double?>(
stream: getFundData(),
builder: (context, snapshort) {
if (snapshort.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
}
if (snapshort.hasData) {
double data = snapshort.data!;
return Center(child: Column(
children: [
Text("$data"),
],
));
}
return Text("data");
},
),
)),
);
function code
Stream<double> getFundData() async* {
final result =
await FirebaseFirestore.instance.collection('Use-of-fund').get();
double totalFundAmount = 0;
for (var doc in result.docs) {
totalFundAmount += doc['Amount'];
}
yield totalFundAmount;
}
Stream<double> getUserBalanceData() async* {
final result = await FirebaseFirestore.instance.collection('User-data').get();
double userTotalAmount = 0;
for (var doc in result.docs) {
userTotalAmount += doc['Balance'];
}
yield userTotalAmount;
}
Now I want to sum userTotalAmount and totalFundAmount