Repository navigation
fix: prevent LateInitializationError when viewer state modified before layout - #2294
Merged
JaffaKetchup merged 7 commits intoDec 1, 2026
Merged
Conversation
JaffaKetchup
requested changes
Nov 22, 2026
JaffaKetchup
left a comment
Member
There was a problem hiding this comment.
See #2293 (comment).
I think a better fix would be to fix onMapReady not to be called to early, unless that is difficult for some reason.
This was referenced Nov 25, 2026
JaffaKetchup
approved these changes
Dec 1, 2026
JaffaKetchup
left a comment
Member
There was a problem hiding this comment.
Although I'm cautious about changing this particular part of the code since it's been the culprit for many bugs before, I think this change is good to go.
Thanks!
LateInitializationError when controller used before layout
LateInitializationError when controller used before layoutLateInitializationError when viewer state modified before layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2293
MapControllerImpl._interactiveViewerStateislateand only assigned once the map'sMapInteractiveVieweris created, which happens during layout.onMapReadyfires after the first frame regardless, so aFlutterMapthat is built but not laid out (e.g. on a route covered by another route from the first frame) throwsLateInitializationErroron any controller move (_emitMapEvent) and on anyinteractionOptionschange (options=). See the issue for the details and a minimal app.Changes
_interactiveViewerStateis now nullable.options=skipsupdateGestureswhile there is no viewer. The viewer builds its gestures from the controller's current options indidChangeDependencies, so it starts out with the latest options._emitMapEventskipsinterruptAnimatedMovementwhile 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:onMapReadydoes not throw, and the move is kept once the map is shown;Both tests fail on
masterwithLateInitializationError: Field '_interactiveViewerState@…' has not been initialized.and pass with this change. The full suite passes (142 tests) anddart analyzeis clean.