I have a list of locations that I want to display on a map and also want to filter by a category. I can get the locations and place markers, but don't know how to filter them when an option from a dropdown is selected for example.
This is what I have so far:
getActiveLocations() {
Stream<List<LocationModel>> locations =
_locationController.getActiveLocations();
locations.listen((location) async {
print(location);
for (var i = 0; i < location.length; i++) {
String name = location[i].name;
double lat = location[i].geometry['location']['lat'];
double lng = location[i].geometry['location']['lng'];
String icon = location[i].icon;
final http.Response response = await http.get(icon);
_markers.add(
Marker(
icon: BitmapDescriptor.fromBytes(response.bodyBytes),
markerId: MarkerId(name),
position: LatLng(lat, lng),
onTap: () => _showModalSheet(location[i]),
),
);
}
});
}
Stream<List<LocationModel>> getActiveLocations() {
final CollectionReference ref = _db.collection('locations');
try {
return ref.snapshots().map(
(QuerySnapshot list) => list.documents
.map((DocumentSnapshot doc) => LocationModel.fromFirestore(doc))
.toList(),
);
} catch (err) {
print(err);
}
return null;
}
Only thing I can think of is setting a state value onTap and then add to _markers
only if the location contains the value.