September 2019
Beginner
512 pages
12h 52m
English
As said before, we need to pass the markers during the GoogleMap widget construction, so the first step is to make our MapPage widget a StatefulWidget widget and rebuild its subtree every time we want to add a new marker.
After that, we need to add a button to the layout so that we can add the marker after the initial build. The onPressed button callback calls _addMarkerOnCameraCenter, as follows::
void _addMarkerOnCameraCenter() { setState(() { _markers.add(Marker( markerId: MarkerId("${_markers.length + 1}"), infoWindow: InfoWindow(title: "Added marker"), icon: BitmapDescriptor.defaultMarker, position: _cameraCenter, )); }); }
As you can see, it uses the setState method to cause a rebuild of the widget and adds ...
Read now
Unlock full access