我想在我的Flatter应用程序中对两个不同的firebase集合字段值求和.这就是我编写两个函数的原因.我可以对一个集合字段值求和,但单个文本小部件中的两个集合字段值求和不起作用,或者我不知道如何执行此操作..
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");
},
),
)),
);
功能代码
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;
}
现在我想求和userTotalAmount和totalFundAmount