Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: PageView control#6158

Merged
FeodorFitsner merged 10 commits intomainfrom
pageview
Feb 12, 2026
Merged

feat: PageView control#6158
FeodorFitsner merged 10 commits intomainfrom
pageview

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Feb 11, 2026

Fix #5248

Test code

import flet as ft


def main(page: ft.Page):
    page.padding = 0

    page.add(
        ft.PageView(
            expand=True,
            viewport_fraction=0.9,
            on_change=lambda e: print(f"Currently viewing page {int(e.data)}"),
            selected_index=1,
            horizontal=True,
            controls=[
                ft.Container(
                    bgcolor=ft.Colors.INDIGO_400,
                    content=ft.Column(
                        alignment=ft.MainAxisAlignment.CENTER,
                        horizontal_alignment=ft.CrossAxisAlignment.CENTER,
                        controls=[
                            ft.Text("Welcome", size=40, weight=ft.FontWeight.BOLD),
                            ft.Text("Swipe to see what PageView can do."),
                        ],
                    ),
                ),
                ft.Container(
                    bgcolor=ft.Colors.PINK_300,
                    content=ft.Column(
                        alignment=ft.MainAxisAlignment.CENTER,
                        horizontal_alignment=ft.CrossAxisAlignment.CENTER,
                        controls=[
                            ft.Icon(ft.Icons.ANIMATION, size=72),
                            ft.Text(
                                "Viewport fraction lets you peek at the next slide."
                            ),
                        ],
                    ),
                ),
                ft.Container(
                    bgcolor=ft.Colors.TEAL_300,
                    content=ft.Column(
                        alignment=ft.MainAxisAlignment.CENTER,
                        horizontal_alignment=ft.CrossAxisAlignment.CENTER,
                        controls=[
                            ft.Icon(ft.Icons.TOUCH_APP, size=72),
                            ft.Text("Use on_change to respond to page swipes."),
                        ],
                    ),
                ),
            ],
        ),
    )


if __name__ == "__main__":
    ft.run(main)

Summary by Sourcery

Introduce a new PageView control for swipable, paginated content and wire it into the Flutter and Python Flet runtimes.

New Features:

  • Add a PageView layout control to the Python SDK with paging configuration and programmatic navigation APIs.
  • Implement the corresponding Flutter PageViewControl widget and register it in the Flet core extension for runtime support.

Enhancements:

  • Expose PageView from the Python flet package and add its user documentation page to the mkdocs navigation.
  • Provide basic and programmatic-swipe PageView examples and an integration screenshot test to validate rendering.
  • Fix a small formatting issue in the Badge control documentation string.

@ndonkoHenri ndonkoHenri linked an issue Feb 11, 2026 that may be closed by this pull request
1 task
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 PageView control implementation in Python and registered it in the public API.
  • Added Flutter-side PageViewControl and 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.

Comment on lines +57 to +60
} else if (newSelectedIndex != _selectedIndex &&
_pageController.hasClients) {
_selectedIndex = newSelectedIndex;
_pageController.jumpToPage(newSelectedIndex);
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
} 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);
});
}

Copilot uses AI. Check for mistakes.
__all__ = ["PageView"]


DEFAULT_ANIMATION_DURATION = Duration(seconds=1)
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
DEFAULT_ANIMATION_DURATION = Duration(seconds=1)
DEFAULT_ANIMATION_DURATION: DurationValue = 1000 # 1 second in milliseconds

Copilot uses AI. Check for mistakes.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 11, 2026

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 10167db
Status:⚡️  Build in progress...

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 11, 2026

Deploying flet-examples with  Cloudflare Pages  Cloudflare Pages

Latest commit: 10167db
Status: ✅  Deploy successful!
Preview URL: https://2766d227.flet-examples.pages.dev
Branch Preview URL: https://pageview.flet-examples.pages.dev

View logs

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.
@FeodorFitsner FeodorFitsner merged commit cf8f743 into main Feb 12, 2026
43 of 48 checks passed
@FeodorFitsner FeodorFitsner deleted the pageview branch February 12, 2026 22:04
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.

feature: PageView control

3 participants