Skip to content

Commit 889b5e0

Browse files
Preserve ResponsiveRow child state across Row/Wrap layout switches (#6663)
* ResponsiveRow: preserve child state across Row/Wrap layout switches 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 * add changelog entry
1 parent 1ba0abe commit 889b5e0

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* Fix `ProgressRing.year_2023` being ignored, so the control correctly switches between the latest and 2023 Material Design appearances ([#6614](https://github.com/flet-dev/flet/issues/6614)) by @ndonkoHenri.
5050
* `flet build ipa` / `ios` apps that ship ctypes packages with plain `.dylib` shared libraries (e.g. `llama-cpp-python`) now load them on the **iOS simulator** instead of failing at launch with a `dlopen` platform mismatch (`have 'iOS', need 'iOS-simulator'`); the iOS runtime also now bundles the `_multiprocessing` extension (importable, not spawnable). Bumps the pinned bundle to `serious_python` 4.2.1 / python-build `20260701` ([serious_python#223](https://github.com/flet-dev/serious-python/pull/223)) by @ndonkoHenri, @FeodorFitsner.
5151
* Improve performance of checking added/removed controls in Session.patch_control from O(N²) to O(N) ([#6651](https://github.com/flet-dev/flet/pull/6651)) by @davidlawson.
52+
* Fix stateful controls inside `ResponsiveRow` (video players, WebViews, scroll positions) losing their state whenever a window resize crossed a breakpoint and the layout switched between a single row and wrapping ([#6661](https://github.com/flet-dev/flet/issues/6661), [#6663](https://github.com/flet-dev/flet/pull/6663)) by @FeodorFitsner.
5253

5354
### Documentation
5455

packages/flet/lib/src/controls/responsive_row.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ class ResponsiveRowControl extends StatelessWidget with FletStoreMixin {
7979
childWidth = 0;
8080
}
8181

82+
// Key the child with a GlobalKey tied to its Control identity so
83+
// that when this build switches between Row and Wrap (a different
84+
// widget type at the same slot), Flutter re-parents the existing
85+
// Element instead of re-inflating the subtree — otherwise stateful
86+
// descendants (video players, WebViews, scroll positions) would
87+
// lose their State on every breakpoint change.
8288
controls.add(ConstrainedBox(
8389
constraints:
8490
BoxConstraints(minWidth: childWidth, maxWidth: childWidth),
85-
child: ControlWidget(key: key, control: ctrl),
91+
child: ControlWidget(key: GlobalObjectKey(ctrl), control: ctrl),
8692
));
8793
}
8894

0 commit comments

Comments
 (0)