-
Notifications
You must be signed in to change notification settings - Fork 645
feat: Page.pop_views_until() to pop multiple views and return a result to the destination view
#6347
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
Open
brunobrown
wants to merge
9
commits into
flet-dev:release/v0.85.0
Choose a base branch
from
brunobrown:pop-until-with-result
base: release/v0.85.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: Page.pop_views_until() to pop multiple views and return a result to the destination view
#6347
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
454b83a
feat: Add pop_until_with_result to Page.
brunobrown 8f25534
docs: add pop_until_with_result demo GIF
brunobrown b1f70e9
refactor: rename to pop_views_until, based on feedback from @ndonkoHenri
brunobrown 05f9c11
test: replace unit tests with integration test for pop_views_until
brunobrown 4c9b005
fix: use distinct text in SnackBar to avoid duplicate match in integr…
brunobrown 65c48d0
fix: align example and test with v0.85.0 directory structure
brunobrown 42854d7
docs: add changelog entry for pop_views_until
brunobrown dc10291
docs: update docstrings to reST cross-refs and fix changelog format
brunobrown b3db8cd
docs: add pop_views_until section to navigation and routing page
brunobrown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
112 changes: 112 additions & 0 deletions
112
sdk/python/examples/apps/routing_navigation/pop_views_until/main.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import asyncio | ||
|
|
||
| import flet as ft | ||
|
|
||
|
|
||
| def main(page: ft.Page): | ||
| page.title = "Routes Example" | ||
|
|
||
| result_text = ft.Text("No result yet", size=18) | ||
|
|
||
| def route_change(): | ||
| page.views.clear() | ||
|
|
||
| # Home View (/) | ||
| page.views.append( | ||
| ft.View( | ||
| route="/", | ||
| controls=[ | ||
| ft.AppBar(title=ft.Text("Home"), bgcolor=ft.Colors.SURFACE_BRIGHT), | ||
| result_text, | ||
| ft.Button( | ||
| "Start flow", | ||
| on_click=lambda _: asyncio.create_task( | ||
| page.push_route("/step1") | ||
| ), | ||
| ), | ||
| ], | ||
| ) | ||
| ) | ||
|
|
||
| if page.route == "/step1" or page.route == "/step2" or page.route == "/step3": | ||
| page.views.append( | ||
| ft.View( | ||
| route="/step1", | ||
| controls=[ | ||
| ft.AppBar( | ||
| title=ft.Text("Step 1"), | ||
| bgcolor=ft.Colors.SURFACE_BRIGHT, | ||
| ), | ||
| ft.Text("Step 1 of the flow"), | ||
| ft.Button( | ||
| "Go to Step 2", | ||
| on_click=lambda _: asyncio.create_task( | ||
| page.push_route("/step2") | ||
| ), | ||
| ), | ||
| ], | ||
| ) | ||
| ) | ||
|
|
||
| if page.route == "/step2" or page.route == "/step3": | ||
| page.views.append( | ||
| ft.View( | ||
| route="/step2", | ||
| controls=[ | ||
| ft.AppBar( | ||
| title=ft.Text("Step 2"), | ||
| bgcolor=ft.Colors.SURFACE_BRIGHT, | ||
| ), | ||
| ft.Text("Step 2 of the flow"), | ||
| ft.Button( | ||
| "Go to Step 3", | ||
| on_click=lambda _: asyncio.create_task( | ||
| page.push_route("/step3") | ||
| ), | ||
| ), | ||
| ], | ||
| ) | ||
| ) | ||
|
|
||
| if page.route == "/step3": | ||
| page.views.append( | ||
| ft.View( | ||
| route="/step3", | ||
| controls=[ | ||
| ft.AppBar( | ||
| title=ft.Text("Step 3 (Final)"), | ||
| bgcolor=ft.Colors.SURFACE_BRIGHT, | ||
| ), | ||
| ft.Text("Flow complete!"), | ||
| ft.Button( | ||
| "Finish and go Home", | ||
| on_click=lambda _: asyncio.create_task( | ||
| page.pop_views_until("/", result="Flow completed!") | ||
| ), | ||
| ), | ||
| ], | ||
| ) | ||
| ) | ||
|
|
||
| page.update() | ||
|
|
||
| def on_pop_result(e: ft.ViewsPopUntilEvent): | ||
| result_text.value = f"Result: {e.result}" | ||
| page.show_dialog(ft.SnackBar(ft.Text(f"Got result: {e.result}"))) | ||
| page.update() | ||
|
|
||
| async def view_pop(e: ft.ViewPopEvent): | ||
| if e.view is not None: | ||
| page.views.remove(e.view) | ||
| top_view = page.views[-1] | ||
| await page.push_route(top_view.route) | ||
|
|
||
| page.on_route_change = route_change | ||
| page.on_view_pop = view_pop | ||
| page.on_views_pop_until = on_pop_result | ||
|
|
||
| route_change() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ft.run(main) |
26 changes: 26 additions & 0 deletions
26
sdk/python/examples/apps/routing_navigation/pop_views_until/pyproject.toml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| [project] | ||
| name = "apps-routing-navigation-pop-views-until" | ||
| version = "1.0.0" | ||
| description = "Pops multiple views from the navigation stack and returns a result to the destination view." | ||
| requires-python = ">=3.10" | ||
| keywords = ["apps", "routing", "navigation", "pop", "views", "result", "async"] | ||
| authors = [{ name = "Flet team", email = "hello@flet.dev" }] | ||
| dependencies = ["flet"] | ||
|
|
||
| [dependency-groups] | ||
| dev = ["flet-cli", "flet-desktop", "flet-web"] | ||
|
|
||
| [tool.flet.gallery] | ||
| categories = ["Apps/Navigation"] | ||
|
|
||
| [tool.flet.metadata] | ||
| title = "Pop views until" | ||
| controls = ["View", "AppBar", "Button", "Text", "SnackBar"] | ||
| layout_pattern = "multi-step-flow" | ||
| complexity = "intermediate" | ||
| features = ["routing", "view stack", "pop views until", "result passing", "async"] | ||
|
|
||
| [tool.flet] | ||
| org = "dev.flet" | ||
| company = "Flet" | ||
| copyright = "Copyright (C) 2023-2026 by Flet" |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.