ViewportController class

A controller for imperatively changing the map's viewport with animations.

Use ViewportController when you need to animate the camera to a new position in response to user actions or other events. For static camera positioning, use MapWidget.viewport instead.

The controller follows the same pattern as TextEditingController or ScrollController: create it, pass it to MapWidget.viewportController, call moveTo to animate, and dispose when done.

class _MyWidgetState extends State<MyWidget> {
  final _viewportController = ViewportController();

  void _flyToNewYork() {
    _viewportController.moveTo(
      CameraViewportState(
        center: Point(coordinates: Position(-74.0, 40.7)),
        zoom: 12,
      ),
      transition: FlyViewportTransition(duration: Duration(seconds: 2)),
      completion: (finished) => print('Animation finished: $finished'),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MapWidget(
      viewport: CameraViewportState(center: Point(coordinates: Position(0, 0))),
      viewportController: _viewportController,
    );
  }

  @override
  void dispose() {
    _viewportController.dispose();
    super.dispose();
  }
}
Inheritance

Constructors

ViewportController.new()

Properties

hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state ViewportState?
The current viewport state, or null if moveTo has not been called yet.
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
inherited
moveTo(ViewportState state, {ViewportTransition? transition = const DefaultViewportTransition(), void completion(bool)?}) → void
Animates the map camera to the given state.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited