Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
880 views
Welcome To Ask or Share your Answers For Others

1 Answer

Probably doc.data()['count'] is an int but you need a String. So call doc.data()['count'].toString().

DocumentSnapshot is not shown but it seems data is a Map<String, dynamic>.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...