如何使用 FloatingActionButton 切换 goole 地图中标记列表的可见性? 或者,开关按钮也应该起作用。
这是我添加标记的功能:
void addAll() async {
_markers = Set<Marker>();
int i = 0;
if(_markerList.length > 0) {
for (i = 0; i < _markerList.length; i++) {
_markers.add(Marker(
markerId: MarkerId(i.toString()),
position: LatLng(_markerList[i].latitude!,
_markerList[i].longitude!),
icon: BitmapDescriptor.fromBytes(markerIcon!),
));
//}
}
}
setState(() {});
}
我用变量管理可见性:
bool isVisible = true;
这是我的
FloatingActionButton
,我想在其中管理可见性:
Padding(
padding: EdgeInsets.all(16.0),
child: Align(
alignment: Alignment.bottomRight,
child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Builder(
builder: (context) => FloatingActionButton(
child: Icon(Icons.location_pin),
onPressed: () {
isVisible ? isVisible = false : isVisible = true;
if(isVisible){
//Create the the new visible marker list here
}
else {
//Create the the new non visible marker list here
}
}),
),
])),
)
要删除特定标记,只需传递标记 ID 即可。它将查找它是否可用并将其删除,否则什么都不做:
Marker marker = _markers.firstWhere((marker) => marker.markerId.value == "your_marker_id",orElse: () => null);
setState(() {
_markers.remove(marker);
});
要删除所有标记,只需将空映射分配给标记变量即可:
setState(() {
_markers = {};
});