Repository navigation
fix: View.on_size_change not firing; deprecate View layout properties - #7088
Draft
ndonkoHenri wants to merge 6 commits into
Draft
ndonkoHenri wants to merge 6 commits into
ndonkoHenri wants to merge 6 commits into
Conversation
ViewControl.build never wrapped its result in LayoutControl, the only place SizeChangeObserver is attached, so View.on_size_change never fired and the layout properties View inherits (margin, opacity, rotate, scale, animate_*) were ignored.
Covers the fix for #6363 (ViewControl now wraps its Scaffold in LayoutControl) at two levels. Flutter widget tests (`packages/flet/test/widgets/view_test.dart`, a `View` group; each builds Page/View controls by hand, renders the real ViewControl and records the events it sends): - reports its size through on_size_change: 800x600 when shown, then 1024x700 after the test surface is resized; - sends no size events without on_size_change; - applies inherited layout properties: margin 20/30 shrinks the Scaffold to 760x540 and opacity 0.5 adds an Opacity widget; - keeps its scaffold state when on_size_change is toggled at runtime, and stops sending events once it is turned off; - a covered view reports the new size once uncovered: with two views stacked only the top one reports a resize, and the bottom one reports the new size when the top one is popped. Without the fix, all but the "no size events" test fail. Integration test (`integration_tests/controls/core/test_view.py`, `test_on_size_change`, real desktop client): shows a View with an on_size_change handler in a 600x450 page, checks the handler gets 600x450, shrinks the window by 100x50 and checks it gets the new size. Passes on macOS with the fix (68 s) and fails without it ("on_size_change didn't fire when the view was shown"). The second step changes the window size by a delta, since `resize_page()` called twice in a row mis-sizes the window while Python's page size lags the first resize.
Adds the pull request link next to the issue link in the 1.1.3 bug-fix entry for View.on_size_change and View's inherited layout properties.
Deploying flet-website-v2 with
|
| Latest commit: |
0d0fd7a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a4dc5fdf.flet-website-v2.pages.dev |
| Branch Preview URL: | https://fix-view-layout-props-6363.flet-website-v2.pages.dev |
…-6363 # Conflicts: # CHANGELOG.md
`View` inherited `LayoutControl` (since the 1.0 alpha), but a view is a route that always fills its page, so none of the inherited size, position, alignment, transform or animation properties could apply, and the client never applied them. Wrapping the whole view in `LayoutControl` made some of them work but also restyled the boot/reconnect screen, turned `left`/`top`/ `animate_position` into the "positioned control outside a Stack" error widget, and rebuilt the boot screen when properties were toggled. Instead, fix the class: - Python: `View` now extends `ScrollableControl` only, like 0.28's `View` and today's `Page`. It declares its own `on_size_change` (with `LayoutSizeChangeEvent["View"]`) and `size_change_interval`. The 27 fields it inherited from `LayoutControl` (`width`, `height`, `min_*`/`max_*`, `left`/`top`/`right`/`bottom`, `align`, `margin`, `rotate`, `scale`, `offset`, `flip`, `transform`, `aspect_ratio`, the `animate_*` options and `on_animation_end`) stay declared on `View` with `V.deprecated` (1.2.0, removed in 1.5.0), so existing code keeps working and gets a warning. - Dart: `ViewControl` returns its result as before and only wraps the body in `SizeChangeObserver` when there is a `size_change` handler. The body has a `GlobalKey`, so its scroll state and open dialogs survive the wrapper being added or removed. Nothing else in the tree changes. - `on_size_change` reports the body's size: the area between the app bar and the bottom navigation bar or bottom app bar, including `padding`, which shrinks while the on-screen keyboard is shown. `Page.on_resize` gives the whole page's size. Docs: 1.2.0 migration guide `breaking-changes/v1-2-0/view-layout-properties`, listed in the breaking-changes index, the sidebar and a new 1.2.x release notes section. Changelog: new `## 1.2.0` section with the deprecation and the `on_size_change` fix. Tests: - Dart view_test.dart: reports its body size (and the new size after a resize); excludes the app bar (800x550 with a 50px toolbar; fails when the whole view is measured); no events without a handler; scaffold and body state kept when the handler is toggled; a covered view reports the new size once uncovered. Pages built by a test are released in its teardown. The margin/opacity test is removed. - Integration test_view.py: waits for the 600x450 size specifically instead of any first event, and skips on web and mobile, where the window can't be resized. - Dart suite 188 passed, flet Python suite 558 passed, the integration test passes on the macOS desktop client, docs build passes all checks.
ndonkoHenri
marked this pull request as draft
November 19, 2026 21:09
View.on_size_change and inherited layout properties ignoredView.on_size_change not firing; deprecate View layout properties
This branch has not been deployed
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 #6363. Targets 1.2.0 (it deprecates API), so it's a draft until 1.1.3 is out.
View.on_size_changenever fired, and none of the propertiesViewinherits fromLayoutControl(width,left,align,margin, the transforms, theanimate_*options, …) had any effect.Why
Viewhas inheritedLayoutControlsince the 1.0 alpha (0.28'sViewdidn't, andPagedoesn't), butViewControlnever applied it. And it can't, for most of it: a view is a route that always fills its page, so it can't be sized, positioned, aligned or transformed within it. Wrapping the whole view inLayoutControl, as this PR first did, made a few properties work but restyled the boot/reconnect screen with the view's opacity or offset, turnedleft/top/animate_positioninto the "positioned control outside a Stack" error widget, and rebuilt the boot screen when properties were toggled.Change
ViewextendsScrollableControlonly and declares its ownon_size_changeandsize_change_interval. The 27 fields it inherited fromLayoutControlstay onViewas deprecated (V.deprecated, 1.2.0, removed in 1.5.0): code that sets them keeps working and logs a warning, e.g. "View.width property is deprecated since version 1.2.0 and will be removed in version 1.5.0. A View always fills its page, so this property has no effect."ViewControlwraps only its body in the existingSizeChangeObserver, and only when there's asize_changehandler. The body has aGlobalKey, so its scroll state and open dialogs survive the wrapper coming and going. Nothing else in the tree changes.on_size_changereports: the size of the body, the area between the app bar and the bottom navigation bar or bottom app bar (includingpadding), which shrinks while the on-screen keyboard is shown. That's the space a view's content can use, which isn't available any other way;Page.on_resizealready gives the whole page's size.View: layout properties are deprecated"), listed in the breaking-changes index, the sidebar and a new 1.2.x section of the release notes. Changelog: new## 1.2.0section with the deprecation and the fix.Testing
packages/flet/test/widgets/view_test.dart(Viewgroup): reports its body size, and the new size after a resize; the body excludes the app bar (800×550 with a 50 px toolbar, which fails when the whole view is measured); no events without a handler; scaffold and body state kept whenon_size_changeis toggled; a covered view reports the new size once uncovered. Fullpackages/fletsuite: 188 pass.integration_tests/controls/core/test_view.py::test_on_size_change, real macOS desktop client: the handler gets 600×450 when the view is shown, then the new size after the window shrinks by 100×50. It waits for that exact size, and skips on web and mobile.fletsuite: 558 pass. Docs:yarn crocodocs:generateandyarn buildpass all checks; the deprecated fields show the deprecation notice and label on theViewpage.