I tried this function to get a filtered list of pharmacies based on medication. However, I’m not sure if my implementation is correct. Could someone please review my approach and provide feedback or suggestions for improvement?
Future<List<DocumentSnapshot>> filterByMedication(Stream<List<DocumentSnapshot>> pharmaciesStream, String medication) async {
List<DocumentSnapshot> filteredPharmacies = [];
await for (var pharmacies in pharmaciesStream) {
for (var pharmacy in pharmacies) {
var drugsCollection = pharmacy.reference.collection('Drugs');
var drugsSnapshot = await drugsCollection.where('Name', isEqualTo: medication).get();
if (drugsSnapshot.docs.isNotEmpty) {
filteredPharmacies.add(pharmacy);
}
}
}
return filteredPharmacies;
}
New contributor
J_Max is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.