【发布时间】:2021-01-12 12:21:29
【问题描述】:
我无法解决这个问题。 最后我想在主小部件中显示“workout.count”
main.dart
Padding(
padding: const EdgeInsets.only(top: 80),
child: Text(workout.count,
style: TextStyle(fontSize: 12)),
)
main_model
void getWorkoutListRealtime() {
final snapshots =
FirebaseFirestore.instance.collection('workoutlist').snapshots();
snapshots.listen((snapshot) {
final docs = snapshot.docs;
final workoutlist = docs.map((doc) => Workout(doc)).toList();
workoutlist.sort((a, b) => b.createdAt.compareTo(a.createdAt));
this.workoutlist = workoutlist;
notifyListeners();
});
}
锻炼.dart
class Workout {
Workout(DocumentSnapshot doc) {
this.documentReference = doc.reference;
this.title = doc.data()['title'];
this.count = doc.data()['count'];
final Timestamp timestamp = doc.data()['createdAt'];
this.createdAt = timestamp.toDate();
}
String title;
String count;
DateTime createdAt;
bool isDone = false;
DocumentReference documentReference;
}
有人有想法吗?
当然我在stackflow中研究了一些文档, 但我无法恢复
【问题讨论】:
标签: firebase flutter google-cloud-firestore get integer