I Have to use Map the Snapshot as this method
Stream<List<writeTime>> readDataStream() {
final monthData = dateTimeNow('yyyyMMdd');
print(monthData);
final path = APIPath.rdatapath(user);
final reference = FirebaseFirestore.instance
.collection(path);
final snapshots = reference.snapshots();
return snapshots.map((snapshot) => snapshot.docs
.map((snapshot) => writeTime.fromMap(snapshot.data()))
.toList());
}
But Recently I have to Get a Specific Document and I tried this code
Stream<List<writeTime>> readDataStream() {
final monthData = dateTimeNow('yyyyMMdd');
print(monthData);
final path = APIPath.rdatapath(user);
final reference =
FirebaseFirestore.instance.collection(path).doc(monthData);
final snapshots = reference.snapshots();
return snapshots.map((snapshot) => snapshot.docs
.map((snapshot) => writeTime.fromMap(snapshot.data()))
.toList());
}
But I have a error in here
return snapshots.map((snapshot) => snapshot.**docs**
.map((snapshot) => writeTime.fromMap(snapshot.data()))
.toList());
And the error is
The getter 'docs' isn't defined for the type 'DocumentSnapshot<Map<String, dynamic>>'.
Try importing the library that defines 'docs', correcting the name to the name of an existing getter, or defining a getter or field named 'docs'.
And I used This map to get data
factory writeTime.fromMap(Map<String, dynamic> data) {
if (data == null) {
throw AssertionError('data must not be null');
}
final int thour = data['thour'];
final int tmin = data["tmin"];
final int chour = data['chour'];
final int cmin = data["cmin"];
return writeTime(thour: thour, tmin: tmin, chour: chour, cmin: cmin);
}
How I fix this?