Preserve ResponsiveRow child state across Row/Wrap layout switches#6663
Merged
Conversation
Key each child's ControlWidget with a GlobalObjectKey tied to its Control identity so Flutter re-parents existing elements when the layout flips between Row and Wrap on a breakpoint change, instead of unmounting and re-inflating the subtree. Stateful descendants (video players, WebViews, scroll positions) now survive window resizes across breakpoints. Fixes #6661
Deploying flet-website-v2 with
|
| Latest commit: |
2886465
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://268d8446.flet-website-v2.pages.dev |
| Branch Preview URL: | https://fix-responsive-row-state-pre.flet-website-v2.pages.dev |
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.
Description
ResponsiveRowControl.build()returns aRowwhen the resolvedcolvalues fit withincolumnsand aWrapwhen they don't. When a window resize crosses a breakpoint, the widget type at that slot changes, so Flutter's reconciliation unmounts the whole child subtree and inflates a new one — destroying any FlutterStatebelow (video players, WebViews, scroll positions, focus).This PR keys each child's
ControlWidgetwith aGlobalObjectKeytied to itsControlmodel identity. Since Dart-sideControlinstances are patched in place, the key is stable across rebuilds with no cache, and Flutter re-parents the existing elements into the newRow/Wrapwithin the same frame — child state now survives breakpoint changes.This also fixes a latent bug on the same line: the
ResponsiveRowControl's own widgetkeywas passed to every child'sControlWidget, which would produce duplicate-key errors if ever non-null.Verification
Scripted repro with a scrollable
ColumninsideResponsiveRow(scroll offset lives in FlutterState, same class of state as a video player's): scroll to 300, resize the window 900→500 px across the MD breakpoint, probe withscroll_to(delta=5).Before (0.86 client): offset resets to 0 on every Row↔Wrap flip (probe lands at 5).
After: offset is preserved (probe lands at 305, and 310 after flipping back).
Related issues
Fixes #6661
Summary by Sourcery
Preserve ResponsiveRow children’s widget state when switching between Row and Wrap layouts by stabilizing their identity-based keys.
Bug Fixes:
Enhancements: