I’m have been trying to get all data of collection a and subcollection b and insert them into a List of model to use that list later to show data in a ListView builder , problems are:
1- I can’t get any data in await col.get(); ( it keeps showing out of memory error so I used await col.limit(20).get() and it shows 20 data normally)
2- I can’t insert data into that list, it gives me this error :
A value of type 'allReport' can't be assigned to a variable of type 'List<allReport>'
Try changing the type of the variable, or casting the right-hand type to 'List<allReport>'.
This is my code
Future<List<allReport>> updateAlldocs() async {
var col = await _firestore.collectionGroup('visits');
var snapshotChild = await col.limit(20).get();
snapshotChild.docs.map((doc) async {
var ChildDocument = doc;
var snapshot_parent = await _firestore
.collection('doctors')
.doc(ChildDocument.reference.parent.parent?.id)
.get();
print('>>>>>>>>>>>>>>>>>>>>>>>>>>${snapshot_parent.data()}');
_docReports = allReport.fromJson(
ChildDocument.data() ,snapshot_parent.data()?['name'] ,doc.reference.parent.parent?.id ?? ''); // here it keeps giving me the errors (2) showed above in the question
}).toList();
print('********************** doctoreName: ${_docReports.map((e) => e.doctoreName)}');
setState(() {
_filtereddocReports = _docReports;
});
return _filtereddocReports;
}
I also tried to assign snapshotChild to _docReports as this:
Future<List<allReport>> updateAlldocs() async {
var col = await _firestore.collectionGroup('visits');
var snapshotChild = await col.limit(20).get();
_docReports = snapshotChild.docs.map((doc) async {
var ChildDocument = doc;
var snapshot_parent = await _firestore
.collection('doctors')
.doc(ChildDocument.reference.parent.parent?.id)
.get();
print('>>>>>>>>>>>>>>>>>>>>>>>>>>${snapshot_parent.data()}');
allReport.fromJson(
ChildDocument.data() ,snapshot_parent.data()?['name'] ,doc.reference.parent.parent?.id ?? '');
}).cast<allReport>().toList();
print('********************** doctoreName: ${_docReports.map((e) => e.doctoreName)}');
// result is: (********************** doctoreName: 0)
setState(() {
_filtereddocReports = _docReports;
});
return _filtereddocReports;
}