I have created two collections as follows: users - documentId(uid from auth) - fields and and sub collection (locations)
opportunities - (auto generated document Id) - Fields (One of the field is locationDocumentId from above collection)
I am retrieving opportunities as Stream where I created a Map in Opportunity class.
I would like to have Location object reference in Opportunity class and populate the object while retrieving opportunities.
I am very new to Firestore and Flutter and got stuck here.
Please advise how I can accomplish this.
Thank you.
Code to get opportunities
// ALL Opportunities
Stream<List<Opportunity>> get opportunities {
return _oppRef
.orderBy('lastUpdated', descending: true)
.snapshots()
.map(_allOpportunitiesFromSnapshot);
}
List<Opportunity> _allOpportunitiesFromSnapshot(QuerySnapshot snapshot) {
return snapshot.documents.map((doc) {
return Opportunity.fromMap(doc.data, doc.documentID);
//HERE I WANTED TO ADD CODE TO GET LOCATION AS
//var opp = Opportunity.fromMap(doc.data, doc.documentID);
// opp.location ???
}).toList();
}
//
Future<DocumentSnapshot> getLocation(
String locationId, String createdBy) async {
return await _docRef
.document(createdBy)
.collection('locations')
.document(locationId)
.get();
}