1

Markers properties are set to final so can not be alters. There is no setter method to change their values without trying to recreate all markers again.

I have trie the following:

  markers.update(_markerId, (Marker m) {
      print(m.markerId);
      return Marker(markerId: MarkerId("2"), infoWindow: InfoWindow(title: "Test"));
    });

The above code just hides the last marker and nothing else

Fazza
  • 11
  • 3

1 Answers1

3

You can not change the properties of the existing marker object yet because they are declared as final.

What you can do is create a copy of that marker object in another marker and then change the property and replace with it. something like this.

 final Marker marker = markers[selectedMarker];
    setState(() {
      markers[selectedMarker] = marker.copyWith(
        visibleParam: !marker.visible,
      );
    });

Credits: Code snippet taken from official google map flutter plugin example.

More examples here https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/example/lib

Pinkesh Darji
  • 1,041
  • 10
  • 23
  • That link is now 404'd - you can find a visibility example here: https://github.com/flutter/plugins/blob/master/packages/google_maps_flutter/google_maps_flutter/example/lib/place_marker.dart – Sludge Dec 09 '20 at 14:45