-
Notifications
You must be signed in to change notification settings - Fork 645
feat: make NavigationDrawerDestination.label accept custom controls
#6395
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
ndonkoHenri
wants to merge
18
commits into
release/v0.85.0
Choose a base branch
from
nav-drawer-label
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
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3cc23bc
initial commit
ndonkoHenri 98c21e1
feat: Add icon theme support for NavigationDrawer
ndonkoHenri 8656015
add test for theming example
ndonkoHenri c9ae79a
feat: Implement navigation drawer with responsive layout
ndonkoHenri 5288a42
fix: remove UV_CACHE_DIR in Taskfile
ndonkoHenri ad1458e
Merge remote-tracking branch 'origin/release/v0.85.0' into nav-drawer…
ndonkoHenri e41b89f
update changelog
ndonkoHenri 01fc6ae
feat: add skill for writing changelog entries
ndonkoHenri a554be0
feat: update changelog guidelines for clarity and consistency
ndonkoHenri 8298b93
Merge remote-tracking branch 'origin/release/v0.85.0' into nav-drawer…
ndonkoHenri f6722e0
refactor widget building logic for improved clarity
ndonkoHenri 3e7c4a1
fix: correct method reference formatting in SKILL.md
ndonkoHenri ce8b032
feat: enhance SKILL.md with target release audit guidelines for depre…
ndonkoHenri beb09c2
docs: update SKILL.md with enhanced guidelines for using CrocoDocs xr…
ndonkoHenri c9b1845
docs: enhance SKILL.md with same-class shorthand usage examples for C…
ndonkoHenri 811697c
review fixes
ndonkoHenri 640f57a
update skills, remove xref syntax
ndonkoHenri 793bbf4
Merge remote-tracking branch 'origin/release/v0.85.0' into nav-drawer…
ndonkoHenri 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
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
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
143 changes: 143 additions & 0 deletions
143
sdk/python/examples/controls/navigation_drawer/adaptive_navigation/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,143 @@ | ||
| import flet as ft | ||
|
|
||
| DESTINATIONS = [ | ||
| ("Messages", ft.Icons.WIDGETS_OUTLINED, ft.Icons.WIDGETS), | ||
| ("Profile", ft.Icons.FORMAT_PAINT_OUTLINED, ft.Icons.FORMAT_PAINT), | ||
| ("Settings", ft.Icons.SETTINGS_OUTLINED, ft.Icons.SETTINGS), | ||
| ] | ||
|
|
||
|
|
||
| def main(page: ft.Page): | ||
| page.theme_mode = ft.ThemeMode.LIGHT | ||
| page.padding = 0 | ||
|
|
||
| screen_index = 0 | ||
|
|
||
| def build_page_index_text() -> ft.Text: | ||
| return ft.Text(f"Page Index = {screen_index}", size=24) | ||
|
|
||
| def set_screen(index: int): | ||
| nonlocal screen_index | ||
| screen_index = index | ||
| render() | ||
|
|
||
| def build_navigation_bar() -> ft.NavigationBar: | ||
| def handle_nav_bar_change(e: ft.Event[ft.NavigationBar]): | ||
| set_screen(e.control.selected_index) | ||
|
|
||
| return ft.NavigationBar( | ||
| selected_index=screen_index, | ||
| on_change=handle_nav_bar_change, | ||
| destinations=[ | ||
| ft.NavigationBarDestination( | ||
| label=label, | ||
| icon=icon, | ||
| selected_icon=selected_icon, | ||
| ) | ||
| for label, icon, selected_icon in DESTINATIONS | ||
| ], | ||
| ) | ||
|
|
||
| def build_navigation_rail() -> ft.NavigationRail: | ||
| def handle_nav_rail_change(e: ft.Event[ft.NavigationRail]): | ||
| if e.control.selected_index is not None: | ||
| set_screen(e.control.selected_index) | ||
|
|
||
| return ft.NavigationRail( | ||
| min_width=50, | ||
| selected_index=screen_index, | ||
| use_indicator=True, | ||
| on_change=handle_nav_rail_change, | ||
| destinations=[ | ||
| ft.NavigationRailDestination( | ||
| label=label, | ||
| icon=icon, | ||
| selected_icon=selected_icon, | ||
| ) | ||
| for label, icon, selected_icon in DESTINATIONS | ||
| ], | ||
| ) | ||
|
|
||
| def build_end_drawer() -> ft.NavigationDrawer: | ||
| async def handle_drawer_change(e: ft.Event[ft.NavigationDrawer]): | ||
| set_screen(e.control.selected_index) | ||
| await page.close_end_drawer() | ||
|
|
||
| return ft.NavigationDrawer( | ||
| selected_index=screen_index, | ||
| on_change=handle_drawer_change, | ||
| controls=[ | ||
| ft.Container( | ||
| padding=ft.Padding.only(left=28, top=16, right=16, bottom=10), | ||
| content=ft.Text( | ||
| "Header", theme_style=ft.TextThemeStyle.TITLE_SMALL | ||
| ), | ||
| ), | ||
| *[ | ||
| ft.NavigationDrawerDestination( | ||
| label=label, | ||
| icon=icon, | ||
| selected_icon=selected_icon, | ||
| ) | ||
| for label, icon, selected_icon in DESTINATIONS | ||
| ], | ||
| ], | ||
| ) | ||
|
|
||
| def build_bottom_bar_layout() -> ft.SafeArea: | ||
| return ft.SafeArea( | ||
| expand=True, | ||
| content=ft.Container( | ||
| expand=True, | ||
| alignment=ft.Alignment.CENTER, | ||
| content=build_page_index_text(), | ||
| ), | ||
| ) | ||
|
|
||
| def build_drawer_layout() -> ft.SafeArea: | ||
| async def open_drawer(e: ft.Event[ft.Button]): | ||
| await page.show_end_drawer() | ||
|
|
||
| return ft.SafeArea( | ||
| expand=True, | ||
| avoid_intrusions_top=False, | ||
| avoid_intrusions_bottom=False, | ||
| content=ft.Row( | ||
| expand=True, | ||
| controls=[ | ||
| ft.Container( | ||
| padding=ft.Padding.symmetric(horizontal=5), | ||
| content=build_navigation_rail(), | ||
| ), | ||
| ft.VerticalDivider(thickness=1, width=1), | ||
| ft.Column( | ||
| expand=True, | ||
| alignment=ft.MainAxisAlignment.SPACE_EVENLY, | ||
| horizontal_alignment=ft.CrossAxisAlignment.CENTER, | ||
| controls=[ | ||
| build_page_index_text(), | ||
| ft.Button("Open Drawer", on_click=open_drawer), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ) | ||
|
|
||
| def render(): | ||
| page.clean() | ||
| if (page.width or page.window.width) >= 450: # wide layout | ||
| page.navigation_bar = None | ||
| page.end_drawer = build_end_drawer() | ||
| page.add(build_drawer_layout()) | ||
| else: # narrow layout | ||
| page.end_drawer = None | ||
| page.navigation_bar = build_navigation_bar() | ||
| page.add(build_bottom_bar_layout()) | ||
| page.update() | ||
|
|
||
| page.on_resize = lambda e: render() | ||
| render() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ft.run(main) |
26 changes: 26 additions & 0 deletions
26
sdk/python/examples/controls/navigation_drawer/adaptive_navigation/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 = "navigation-drawer-adaptive-navigation" | ||
| version = "1.0.0" | ||
| description = "Demonstrates adaptive navigation with NavigationBar on narrow layouts and NavigationRail plus NavigationDrawer on wide layouts." | ||
| requires-python = ">=3.10" | ||
| keywords = ["navigation drawer", "navigation rail", "navigation bar", "adaptive navigation", "responsive"] | ||
| authors = [{ name = "Flet team", email = "hello@flet.dev" }] | ||
| dependencies = ["flet"] | ||
|
|
||
| [dependency-groups] | ||
| dev = ["flet-cli", "flet-desktop", "flet-web"] | ||
|
|
||
| [tool.flet.gallery] | ||
| categories = ["Navigation/NavigationDrawer"] | ||
|
|
||
| [tool.flet.metadata] | ||
| title = "Adaptive Navigation" | ||
| controls = ["NavigationDrawer", "NavigationDrawerDestination", "NavigationRail", "NavigationRailDestination", "NavigationBar", "NavigationBarDestination", "Button", "SafeArea", "Container", "Row", "Column", "VerticalDivider", "Text", "Page"] | ||
| layout_pattern = "adaptive-navigation" | ||
| complexity = "intermediate" | ||
| features = ["responsive layout", "adaptive navigation", "end drawer", "navigation rail", "navigation bar"] | ||
|
|
||
| [tool.flet] | ||
| org = "dev.flet" | ||
| company = "Flet" | ||
| copyright = "Copyright (C) 2023-2026 by Flet" |
Oops, something went wrong.
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.