I have dynamically created Markers with LabelMarkers. I add all of them to a Set of Markers to use on GoogleMap.
static Set<Marker> allMarkers = {};
...
allLocationsList.forEach((location) async {
...
allMarkers.addLabelMarker(
LabelMarker(
visible: **_isItVisible**,
label: _name,
markerId: MarkerId(_name),
draggable: false,
backgroundColor: **_amIclose**
? Colors.green
: Colors.red,
position: LatLng(_latitude, _longitude),
onTap: **_isItEnabled**
? pressButton()
: null,
),
);
}
...
return GoogleMap(
style: _mapStyle,
gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
Factory<OneSequenceGestureRecognizer>(
() => EagerGestureRecognizer(),
),
},
zoomGesturesEnabled: true,
tiltGesturesEnabled: false,
compassEnabled: true,
rotateGesturesEnabled: true,
scrollGesturesEnabled: true,
mapToolbarEnabled: false,
myLocationEnabled: false,
myLocationButtonEnabled: false,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 6.2,
),
markers: allMarkers,
onMapCreated: (GoogleMapController controller) async {
mapController = controller;
setState(
() {
mapController?.animateCamera(...);
},
);
},
);
As you see I have many variables. _isItVisible, _isItEnabled and _amIclose probably should be checked in a Stream. Now there are two problems:
- I can’t return LabelMaker from StatefulWidget as this is not a Widget (I would use a Stream in every Label to check for variables).
- If I would check and update all Markers constantly in one Stream the app would loose a lot of Frames and “die”.
I have wasted hours and even days to find a way to update only Markers with changed variable (_isItVisible, _isItEnabled and _amIclose) values. Please help!