I cannot resolve this problem. Finally I want to display 'workout.count' in main widget
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();
});
}
workout.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;
}
Does anyone have ideas?
Of course I research some documents in stackflow, but I cannot recover