如何在 flutter 2.0 中对与另一个集合相关的 firestore 集合中的字段值求和
how to sum values of a field inside a firestore collection related to another collection in flutter 2.0
我有点迷路了,我正在尝试获取特定字段的总和,我的代码在这里:
Future _sumCarta() async {
await _firebaseServices.usersRef
.doc(currentUser)
.collection('Cart')
.get()
.then((querySnapshot) {
querySnapshot.docs.forEach((element) async {
// here I want to sum
num value = element.data()["price"];
});
});
}
我想得到所有文件的总和结果,欢迎任何帮助或想法,谢谢
不会是:
num sum = 0.0;
querySnapshot.docs.forEach((element) async {
num value = element.data()["price"];
sum = sum + value;
});
print(sum)
我有点迷路了,我正在尝试获取特定字段的总和,我的代码在这里:
Future _sumCarta() async {
await _firebaseServices.usersRef
.doc(currentUser)
.collection('Cart')
.get()
.then((querySnapshot) {
querySnapshot.docs.forEach((element) async {
// here I want to sum
num value = element.data()["price"];
});
});
}
我想得到所有文件的总和结果,欢迎任何帮助或想法,谢谢
不会是:
num sum = 0.0;
querySnapshot.docs.forEach((element) async {
num value = element.data()["price"];
sum = sum + value;
});
print(sum)