Skip to main content
usage

Programmatic Interaction

MapController drives the camera: flutter_map's controller plus the animated API of flutter_map_animations.AnimatedMapController, because the native maps animate the camera themselves.

Instant calls​

move, rotate, rotateAroundPoint, moveAndRotate, fitCamera behave as flutter_map's on every backend: controller.camera holds the target as soon as the call returns, the move event (MapEventSource.mapController) is emitted and MapOptions.onPositionChanged runs before it, and the native map follows a moment later. The camera is clamped to minZoom / maxZoom and the cameraConstraint. Calls made before onMapReady set the camera the map will be created with.

controller.move(const LatLng(50.85, 4.35), 11);
controller.fitCamera(CameraFit.bounds(bounds: routeBounds, padding: const EdgeInsets.all(24)));

fitCamera uses the native fit when it is exact (a north-up CameraFit.bounds / CameraFit.coordinates without an integer or minimum zoom constraint); every other fit, custom ones included, is solved in Dart.

Animated calls​

animateTo, animatedFitCamera, centerOnPoint / centerOnPoints, the zoom helpers (animatedZoomIn, animatedZoomOut, animatedZoomTo) and the rotation helpers (animatedRotateFrom, animatedRotateTo, animatedRotateReset) are built on animateTo. Without a curve the platform animates with its own easing; with a curve the core drives the camera frame by frame, following it exactly. The future completes when the animation ends or is interrupted — by a gesture, stopAnimations, or a newer animation when cancelPreviousAnimations is true.

External controllers​

final controller = MapController();
// ...
UnifiedMap(mapController: controller, options: options, children: [...]);
  • create it with MapController() and attach it to exactly one UnifiedMap; other implementations are not supported;
  • controller.camera throws until the map is attached — keep it alive until the map is gone, then dispose();
  • MapController.of(context) gives the attached controller to descendants (an UnifiedMapInheritedModel, like flutter_map's).

Reacting to map events​

MapOptions.onMapEvent, or controller.mapEventStream, delivers flutter_map's MapEvents on every backend: start / move / end for drags and multi-finger gestures, the native momentum after a fling, double taps and the zoom they trigger, the scroll wheel, the keyboard, camera moves — with MapEventSource telling who triggered what. MapCamera.of(context) gives descendants the camera as it changes.

takeSnapshot() returns a PNG of the map exactly as the platform draws it (base map, shapes, markers) — not in flutter_map.