【发布时间】:2021-12-21 00:35:36
【问题描述】:
我们正在尝试将 Stream 转换为 Dart Flutter 中的 List。
List<double> _DeadliftWeightsList(QuerySnapshot snapshot){
List <Weights?> weights = snapshot.docs.map((doc){
Weights(
date: doc.get('date') ?? DateTime.now(),
weight: doc.get('deadLiftWeight') ?? 0);
}).toList();
final List<double> normalized = NormalizedData(weights);
return normalized;}
List<double> DLWeights() {
List <double> weights = [];
usersCollection.snapshots()
.map(_DeadliftWeightsList).listen((List<double> weights1) {
weights = weights1;
});
return weights;}
这是我们的返回列表函数
List<double> returnList (String key){
List<double> values = [];
if(key == "Dead Lift"){
values = DLWeights();
}
else if (key == "Back Squat"){
values = BSWeights();
}
else if (key == "Hip Thrust") {
values = HTWeights();
}
else if (key == "Leg Press") {
values = LPWeights();
}
else if (key == "Bench Press") {
values = BPWeights();
}
else if (key == "Lateral Pulldown ") {
values = LateralPDWeights();
}
else if (key == "Bicep Curl") {
values = BCWeights();
}
else if (key == "Tricep Extension") {
values = TEWeights();
}
return values;
}
这些函数旨在从 Stream 中获取数据并返回一个列表。然而,它并没有抓取数据,而是给我们一个糟糕的状态错误。
【问题讨论】:
标签: database flutter dart google-cloud-firestore