Conversation
There was a problem hiding this comment.
Pull request overview
Introduces a new PageView control to the Flet Python SDK with corresponding Flutter (Dart) implementation, documentation, examples, and an integration golden test.
Changes:
- Added
PageViewcontrol implementation in Python and registered it in the public API. - Added Flutter-side
PageViewControland wired it into the control factory. - Added docs, examples, and an integration test with a golden screenshot.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/python/packages/flet/src/flet/controls/material/badge.py | Minor docstring formatting fix. |
| sdk/python/packages/flet/src/flet/controls/core/page_view.py | New Python PageView control API, validation, and invoke methods. |
| sdk/python/packages/flet/src/flet/init.py | Exposes PageView from the top-level flet package. |
| sdk/python/packages/flet/mkdocs.yml | Adds PageView to the documentation navigation. |
| sdk/python/packages/flet/integration_tests/controls/core/test_page_view.py | Adds an integration screenshot test for PageView. |
| sdk/python/packages/flet/integration_tests/controls/core/golden/macos/page_view/basic.png | Adds macOS golden image for the integration test. |
| sdk/python/packages/flet/docs/controls/pageview.md | Adds PageView documentation page and example includes. |
| sdk/python/examples/controls/page_view/basic.py | Adds a basic usage example for PageView. |
| sdk/python/examples/controls/page_view/programmatic_swipe.py | Adds an example demonstrating programmatic page changes. |
| packages/flet/lib/src/flet_core_extension.dart | Registers the new PageView control in the Dart control factory. |
| packages/flet/lib/src/controls/page_view.dart | Implements the Flutter PageViewControl widget and method handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else if (newSelectedIndex != _selectedIndex && | ||
| _pageController.hasClients) { | ||
| _selectedIndex = newSelectedIndex; | ||
| _pageController.jumpToPage(newSelectedIndex); |
There was a problem hiding this comment.
In didUpdateWidget(), when selected_index changes but _pageController.hasClients is false, the new index is ignored and _selectedIndex is not updated. This can leave the widget displaying a different page than the control property if selected_index is updated before the controller attaches. Consider always updating _selectedIndex and either (a) recreating the controller when hasClients is false, or (b) scheduling a jumpToPage() in a post-frame callback once the controller attaches.
| } else if (newSelectedIndex != _selectedIndex && | |
| _pageController.hasClients) { | |
| _selectedIndex = newSelectedIndex; | |
| _pageController.jumpToPage(newSelectedIndex); | |
| } else if (newSelectedIndex != _selectedIndex) { | |
| _selectedIndex = newSelectedIndex; | |
| if (_pageController.hasClients) { | |
| _pageController.jumpToPage(newSelectedIndex); | |
| } else { | |
| WidgetsBinding.instance.addPostFrameCallback((_) { | |
| if (!mounted || !_pageController.hasClients) { | |
| return; | |
| } | |
| _pageController.jumpToPage(_selectedIndex); | |
| }); | |
| } |
| __all__ = ["PageView"] | ||
|
|
||
|
|
||
| DEFAULT_ANIMATION_DURATION = Duration(seconds=1) |
There was a problem hiding this comment.
DEFAULT_ANIMATION_DURATION is a mutable Duration instance that’s reused as the default argument value in go_to_page(), next_page(), and previous_page(). Mutable default arguments can be modified accidentally and then affect subsequent calls. Prefer using None defaults (and assigning Duration(seconds=1) inside the method) or using an immutable default such as an int milliseconds value.
| DEFAULT_ANIMATION_DURATION = Duration(seconds=1) | |
| DEFAULT_ANIMATION_DURATION: DurationValue = 1000 # 1 second in milliseconds |
Deploying flet-examples with
|
| Latest commit: |
10167db
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://2766d227.flet-examples.pages.dev |
| Branch Preview URL: | https://pageview.flet-examples.pages.dev |
Switch page view animations to ft.AnimationCurve.BOUNCE_OUT and shorten animation_duration from 3s to 1s for both show_previous_page and show_next_page in sdk/python/examples/controls/page_view/programmatic_swipe.py to make transitions quicker and use a bounce-out easing.
Fix #5248
Test code
Summary by Sourcery
Introduce a new PageView control for swipable, paginated content and wire it into the Flutter and Python Flet runtimes.
New Features:
Enhancements: