-
Notifications
You must be signed in to change notification settings - Fork 614
feat: LayoutControl.on_size_change event for size-awareness
#6099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've reviewed this pull request using the Sourcery rules engine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a size-change event for layout-based controls, wires it through the Flutter side, and updates container examples, docs, and tests to demonstrate size-aware behavior.
Changes:
- Add
LayoutSizeChangeEvent,on_size_change, andsize_change_intervaltoLayoutControland implement a throttledSizeChangeObserveron the Flutter side, enabling controls to be notified when their rendered size changes. - Update various Flutter plugin controls (maps, charts, ads, video, webview, rive, lottie, datatable2) to wrap content with
LayoutControlinstead ofConstrainedControl, and exposeLayoutSizeChangeEventat the PythonfletAPI. - Refresh container docs and examples (including a new size-aware example and an animated overlay menu), and add integration screenshot tests and goldens for container size-awareness and nested themes.
Reviewed changes
Copilot reviewed 26 out of 32 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/python/packages/flet/src/flet/controls/material/reorderable_list_view.py | Minor doc tweak adding an “Example:” label for the existing ListView example. |
| sdk/python/packages/flet/src/flet/controls/layout_control.py | Introduces LayoutSizeChangeEvent, adds size_change_interval and on_size_change to LayoutControl, and cleans up examples and the deprecated ConstrainedControl alias. |
| sdk/python/packages/flet/src/flet/controls/core/gesture_detector.py | Clarifies the drag_interval documentation wording without changing behavior. |
| sdk/python/packages/flet/src/flet/init.py | Re-exports LayoutSizeChangeEvent and adds it to the public symbol list so it’s available as ft.LayoutSizeChangeEvent. |
| sdk/python/packages/flet/integration_tests/examples/material/test_container.py | Adds screenshot-based integration tests for the size_aware, nested_themes_1, and nested_themes_2 container examples. |
| sdk/python/packages/flet/integration_tests/examples/material/golden/macos/container/size_aware.png | New macOS golden image for the size-aware container example. |
| sdk/python/packages/flet/integration_tests/examples/material/golden/macos/container/nested_themes_2.png | New/updated macOS golden image for the nested_themes_2 container example. |
| sdk/python/packages/flet/integration_tests/examples/material/golden/macos/container/nested_themes_1.png | New macOS golden image for the nested_themes_1 container example. |
| sdk/python/packages/flet/docs/controls/container.md | Simplifies image includes (dropping explicit alt attributes), removes the old background_color example block, and documents the new size-aware and nested theme examples. |
| sdk/python/packages/flet-webview/src/flutter/flet_webview/lib/src/webview.dart | Wraps the platform-specific webview with LayoutControl instead of the now-removed ConstrainedControl widget. |
| sdk/python/packages/flet-video/src/flutter/flet_video/lib/src/video.dart | Uses LayoutControl to wrap the video player widget and slightly tidies playlist construction. |
| sdk/python/packages/flet-rive/src/flutter/flet_rive/lib/src/rive.dart | Wraps both placeholder and loaded rive widgets in LayoutControl, replacing ConstrainedControl. |
| sdk/python/packages/flet-map/src/flutter/flet_map/lib/src/tile_layer.dart | Wraps the tile layer widget in LayoutControl to be consistent with the new layout pipeline. |
| sdk/python/packages/flet-map/src/flutter/flet_map/lib/src/map.dart | Wraps the map widget with LayoutControl instead of ConstrainedControl. |
| sdk/python/packages/flet-lottie/src/flutter/flet_lottie/lib/src/lottie.dart | Uses LayoutControl to host the Lottie animation widget. |
| sdk/python/packages/flet-datatable2/src/flutter/flet_datatable2/lib/src/datatable2.dart | Wraps the DataTable2 widget with LayoutControl. |
| sdk/python/packages/flet-charts/src/flutter/flet_charts/lib/src/scatter_chart.dart | Replaces ConstrainedControl with LayoutControl for scatter chart rendering. |
| sdk/python/packages/flet-charts/src/flutter/flet_charts/lib/src/radar_chart.dart | Replaces ConstrainedControl with LayoutControl for radar chart rendering. |
| sdk/python/packages/flet-charts/src/flutter/flet_charts/lib/src/pie_chart.dart | Replaces ConstrainedControl with LayoutControl for pie chart rendering. |
| sdk/python/packages/flet-charts/src/flutter/flet_charts/lib/src/line_chart.dart | Replaces ConstrainedControl with LayoutControl for line chart rendering. |
| sdk/python/packages/flet-charts/src/flutter/flet_charts/lib/src/candlestick_chart.dart | Replaces ConstrainedControl with LayoutControl for candlestick chart rendering. |
| sdk/python/packages/flet-charts/src/flutter/flet_charts/lib/src/bar_chart.dart | Replaces ConstrainedControl with LayoutControl for bar chart rendering. |
| sdk/python/packages/flet-ads/src/flutter/flet_ads/lib/src/native.dart | Wraps the native ad widget in LayoutControl so it participates in the unified layout/event pipeline. |
| sdk/python/packages/flet-ads/src/flutter/flet_ads/lib/src/banner.dart | Wraps the banner ad widget in LayoutControl. |
| sdk/python/examples/controls/container/size_aware.py | Replaces the custom SizeAwareContainer canvas control with a simpler example using Container.on_size_change and LayoutSizeChangeEvent. |
| sdk/python/examples/controls/container/nested_themes_2.py | Makes the example script runnable as __main__ without side effects on import. |
| sdk/python/examples/controls/container/nested_themes_1.py | Same if __name__ == "__main__": guard pattern added for the first nested themes example. |
| sdk/python/examples/controls/container/background_color.py | Removes the outdated background-color container example, consistent with the docs cleanup. |
| sdk/python/examples/controls/container/animate_4.py | Adds a new example showing an animated slide-in overlay menu using Container.offset and animate_offset. |
| sdk/python/examples/controls/container/init.py | Package file (unchanged content) enabling examples.controls.container imports used by the new tests. |
| packages/flet/lib/src/controls/base_controls.dart | Removes the ConstrainedControl widget, adds a _sizeChangeObserver hook into LayoutControl, and implements SizeChangeObserver/MeasureSize to trigger a throttled "size_change" event with measured w/h. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Deploying flet-docs with
|
| Latest commit: |
047f534
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c879401e.flet-docs.pages.dev |
| Branch Preview URL: | https://size-aware.flet-docs.pages.dev |
Deploying flet-examples with
|
| Latest commit: |
047f534
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c9d1c2a9.flet-examples.pages.dev |
| Branch Preview URL: | https://size-aware.flet-examples.pages.dev |
…tionBar` + update `Tabs` example file paths to use underscores instead of hyphens
| f"selected_index ({self.selected_index}) is out of range. " | ||
| f"Expected a value between 0 and {visible_destinations_count - 1} " | ||
| "inclusive." | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it allowed to have only one tab visible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

Fix #6081
Test code
Summary by Sourcery
Add an opt-in layout size change event to layout-based controls and migrate dependent widgets to use the unified LayoutControl wrapper.
New Features:
Enhancements:
Documentation:
Tests: