fix: don't apply initialCameraFit on a zero-sized camera#2223
Merged
JaffaKetchup merged 2 commits intoJul 2, 2026
Conversation
_applyInitialCameraFit could apply initialCameraFit against a zero-sized camera and mark it as permanently applied, because _parentConstraintsAreSet can return true in exactly that situation (its MediaQuery-based fallback is satisfied almost immediately, independently of whether this widget's own layout has actually settled). This produced a permanent, degenerate (fully zoomed-out) camera position with no way to recover short of user interaction. Added an explicit guard so the fit is only applied - and only latched as applied - once the constraints are genuinely non-zero in both dimensions.
initialCameraFit on a zero-sized camera
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 #2222 - see that issue for the full bug report, reproduction steps and root-cause analysis.
Fix
_applyInitialCameraFitcould applyinitialCameraFitagainst a zero-sized camera (constraints.maxWidth/maxHeight == 0) and mark it as permanently applied, because_parentConstraintsAreSetcan returntruein exactly that situation (itsMediaQuery-based fallback is satisfied almost immediately, independently of whether this widget's own layout has actually settled).Added an explicit, additional guard so the fit is only applied - and only latched as applied - once the constraints are genuinely non-zero in both dimensions:
I deliberately left
_parentConstraintsAreSetitself untouched, rather than rewriting its heuristic - there's no history explaining why theMediaQueryfallback was added, so I didn't want to risk changing behaviour I can't fully verify. This fix instead directly prevents the harmful outcome (latching against a degenerate size) regardless of what_parentConstraintsAreSetdecides. If the real constraints never arrive (the widget is genuinely given zero space forever), the fit simply never applies, which is a strictly better outcome than silently locking in a degenerate zoom.Testing
Added
test/map/zero_size_camera_fit_test.dartwith two cases (there was no existing test coverage forinitialCameraFitat all):FlutterMapmounted inside a widget that reportsSize.zerofor one frame before revealing its real size: asserts the resultingcamera.zoommatches a direct fit against the real size (previously it settled on0.0, the degenerate zoomed-out result).Full existing test suite passes locally with no regressions.
Manually verified on a physical Android device using the reproduction linked in the issue, pointed at this branch via a
dependency_overrides: path:entry.AI disclosure
Per
CONTRIBUTING.md: I used AI assistance (Claude Code) to help diagnose the root cause and draft this fix and its tests. I've reviewed the change, verified it against the project's lint rules and test suite, and manually confirmed the fix resolves the issue on a physical device.