Here's my Google Map widget:
body: Stack(children: <Widget>[
SizedBox(
width: MediaQuery.of(context)
.size
.width,
height: MediaQuery.of(context).size.height,
child:
Consumer<ProviderMaps>(builder: (context, Provmap, widget) {
return GoogleMap(
myLocationEnabled: true,
compassEnabled: true,
mapToolbarEnabled: true,
zoomControlsEnabled: true,
zoomGesturesEnabled: true,
onCameraMove: _onCameraMove,
// onLongPress: Provmap.addMarker,
onLongPress: _addMarkerLongPressed,
myLocationButtonEnabled: false,
mapType: maptype,
onTap: Provmap.addMarker,
markers: markers.values.toSet().union(Provmap.markers),
circles: Set<Circle>.of(circles.values),
polylines: polyline.toSet().union(Provmap.polyline),
polygons: polygon.toSet().union(Provmap.polygon),
initialCameraPosition:
CameraPosition(target: LatLng(lat, lng), zoom: 10.0),
onMapCreated: (GoogleMapController controller) {
mapController = controller;
_controller.complete(controller);
isMapCreated = true;
setState(() {});
});
})),
I'm using Consumer(builder: (context, Provmap, widget) { to pull from Bloc where I build some of my other markers and whatnot. I can clear the items from my consumer with this function:
Consumer<ProviderMaps>(builder: (context, menu, widget) {
return IconButton(
icon: Icon(MdiIcons.trashCan),
color: Color(0xffFFFFFF),
onPressed: menu.deletemap,
);
}),
This is in my bloc:
void deletemap() {
polygon.clear();
markers.clear();
polylines.clear();
polyline.clear();
mpolyline.clear();
polyg.clear();
markers.clear();
notifyListeners();
}
I tried this in my _MyHomePageState:
Consumer<ProviderMaps>(builder: (context, menu, widget) {
return IconButton(
icon: Icon(MdiIcons.trashCan),
color: Color(0xffFFFFFF),
onPressed: () {
menu.deletemap;
polygon.clear();
markers.clear();
polylines.clear();
polyline.clear();
mpolyline.clear();
polyg.clear();
markers.clear();
},
and it didn't work for clearing the markers which came from my bloc. It only cleared markers generated from my original class. Anybody know how to globally clear all items in a map? Is there some special way of calling items from bloc and from my primary class?
Just... need "()" end of your menu.deletemap
function call.
like menu.deletemap()
.
User contributions licensed under CC BY-SA 3.0