Skip to content

fix: allow using MapController before the map has been laid out - #2294

Open
codeOfJannik wants to merge 2 commits into
fleaflet:masterfrom
codeOfJannik:fix/controller-without-viewer
Open

codeOfJannik wants to merge 2 commits into
fleaflet:masterfrom
codeOfJannik:fix/controller-without-viewer

Conversation

@codeOfJannik

Copy link
Copy Markdown

Fixes #2293

MapControllerImpl._interactiveViewerState is late and only assigned once the map's MapInteractiveViewer is created, which happens during layout. onMapReady fires after the first frame regardless, so a FlutterMap that is built but not laid out (e.g. on a route covered by another route from the first frame) throws LateInitializationError on any controller move (_emitMapEvent) and on any interactionOptions change (options=). See the issue for the details and a minimal app.

Changes

  • _interactiveViewerState is now nullable.
  • options= skips updateGestures while there is no viewer. The viewer builds its gestures from the controller's current options in didChangeDependencies, so it starts out with the latest options.
  • _emitMapEvent skips interruptAnimatedMovement while there is no viewer. There is no viewer-driven gesture animation to interrupt.

Behaviour for maps that have been laid out is unchanged.

Tests

New test/map/unlaid_out_map_test.dart, with the map on a route that an opaque route covers from the first frame:

  • moving the camera from onMapReady does not throw, and the move is kept once the map is shown;
  • changing the interaction options before the map is laid out does not throw, and the new options apply once it is (verified by dragging the map).

Both tests fail on master with LateInitializationError: Field '_interactiveViewerState@…' has not been initialized. and pass with this change. The full suite passes (142 tests) and dart analyze is clean.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LateInitializationError on _interactiveViewerState when a MapController is used after onMapReady but before the map has been laid out

1 participant