Skip to content

fix: View.on_size_change not firing; deprecate View layout properties - #7088

Draft
ndonkoHenri wants to merge 6 commits into
mainfrom
fix/view-layout-props-6363
Draft

ndonkoHenri wants to merge 6 commits into
mainfrom
fix/view-layout-props-6363

Conversation

@ndonkoHenri

@ndonkoHenri ndonkoHenri commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6363. Targets 1.2.0 (it deprecates API), so it's a draft until 1.1.3 is out.

View.on_size_change never fired, and none of the properties View inherits from LayoutControl (width, left, align, margin, the transforms, the animate_* options, …) had any effect.

Why

View has inherited LayoutControl since the 1.0 alpha (0.28's View didn't, and Page doesn't), but ViewControl never 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 in LayoutControl, as this PR first did, made a few properties work but restyled the boot/reconnect screen with the view's opacity or offset, turned left/top/animate_position into the "positioned control outside a Stack" error widget, and rebuilt the boot screen when properties were toggled.

Change

  • Python: View extends ScrollableControl only and declares its own on_size_change and size_change_interval. The 27 fields it inherited from LayoutControl stay on View as 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."
  • Dart: ViewControl wraps only its body in the existing SizeChangeObserver, and only when there's a size_change handler. The body has a GlobalKey, so its scroll state and open dialogs survive the wrapper coming and going. Nothing else in the tree changes.
  • What on_size_change reports: the size of the body, 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. That's the space a view's content can use, which isn't available any other way; Page.on_resize already gives the whole page's size.
  • Docs: a 1.2.0 migration guide ("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.0 section with the deprecation and the fix.

Testing

  • Flutter widget tests, packages/flet/test/widgets/view_test.dart (View group): 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 when on_size_change is toggled; a covered view reports the new size once uncovered. Full packages/flet suite: 188 pass.
  • Integration test, 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.
  • Python flet suite: 558 pass. Docs: yarn crocodocs:generate and yarn build pass all checks; the deprecated fields show the deprecation notice and label on the View page.

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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

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

View logs

`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
ndonkoHenri marked this pull request as draft November 19, 2026 21:09
@ndonkoHenri ndonkoHenri changed the title fix: View.on_size_change and inherited layout properties ignored fix: View.on_size_change not firing; deprecate View layout properties Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: View.on_size_change not firing

1 participant