I have an application under construction I want to access, in FIRESTORE I have several countries as a doc and within each country I have a collections and inside the collections I have a list of doc I need access to all.
Stream<List<RecentChat>> getFavo({userId , countryName}) {
List<CountryModel> country;
for(CountryModel c in countryName) {
var ref = _db.collection('country').doc(c.countryName).collection('chat').where("likes", arrayContains: userId).snapshots();
return ref.map((snap) => snap.docs.map((doc) => RecentChat.fromJson(doc.data())).toList());
}
}
Current Behavior: Only the first doc is returned.
Desired Behavior: Return all the docs.
Yes indeed only the first element will be returned, since you are doing a return
in side of the loop and not using the Stream
keyword yield
.
Stream<List<RecentChat>> getFavo({userId , countryName}) {
List<CountryModel> country;
for(CountryModel c in countryName) {
var ref = _db.collection('country').doc(c.countryName).collection('chat').where("likes", arrayContains: userId).snapshots();
yield ref.map((snap) => snap.docs.map((doc) => RecentChat.fromJson(doc.data())).toList());
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.