gpt4 book ai didi

flutter - 如何计算 flutter 名单上的总和?

转载 作者:行者123 更新时间:2023-12-03 04:27:20 25 4
gpt4 key购买 nike

如果我使用此StreamBuilder调用我的snapshot.data.document

StreamBuilder(
stream: Firestore.instance
.collection('col')
.document('doc')
.snapshots(),
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return new Container(
child: Center(
child: CircularProgressIndicator(),
),
);
} else {
Data(document: snapshot.data.documents),
}
},
),

我在类Data()中将此得分值数据称为ListView.builder
ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.only(top: 50.0, bottom: 50.0),
itemCount: document.length,
itemBuilder: (BuildContext context, int i) {
int score = document[i].data['score'];
}

how to get the sum total from that data and display it in AlertDialog?

最佳答案

Future getTotal() async {
int counter = 0;
await Firestore.instance
.collection('post').document('doc').collection('collection')
.snapshots()
.listen((data) =>
data.documents.forEach((doc) => counter += (doc["score"])));
print("The total is $counter");
return counter;
}
}

关于flutter - 如何计算 flutter 名单上的总和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58851047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com