【发布时间】:2020-04-17 15:00:27
【问题描述】:
我有一个位置列表,我想在地图上显示并且还想按类别进行过滤。我可以获取位置和地点标记,但不知道在选择下拉选项时如何过滤它们。
这是我目前所拥有的:
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;
}
我唯一能想到的就是在 onTap 上设置一个状态值,然后仅当位置包含该值时才添加到 _markers。
【问题讨论】:
标签: flutter google-cloud-firestore