Skip to content

Instantly share code, notes, and snippets.

@danialothman
Created November 9, 2023 07:22
Show Gist options
  • Save danialothman/3690e788a505385de104a8408768190c to your computer and use it in GitHub Desktop.
Save danialothman/3690e788a505385de104a8408768190c to your computer and use it in GitHub Desktop.
flet navigationbar - modified sample includes change function - how to simulate navigating between pages via on_change function
# modified sample includes change function
# flet v0.11.0
# sample source: https://flet.dev/docs/controls/navigationbar/
import flet as ft
def main(page: ft.Page):
page.title = "NavigationBar Example"
page_one_ui = ft.Text("Page One")
page_two_ui = ft.Text("Page Two")
page_three_ui = ft.Text("Page Three")
content = ft.Column([page_one_ui])
def change_index(e):
index = page.navigation_bar.selected_index
print(str(index))
if index == 0:
content.controls.pop()
content.controls.append(page_one_ui)
if index == 1:
content.controls.pop()
content.controls.append(page_two_ui)
if index == 2:
content.controls.pop()
content.controls.append(page_three_ui)
page.update()
page.navigation_bar = ft.NavigationBar(
on_change=change_index,
destinations=[
ft.NavigationDestination(
icon=ft.icons.EXPLORE,
label="Explore",
),
ft.NavigationDestination(
icon=ft.icons.COMMUTE,
label="Commute",
),
ft.NavigationDestination(
icon=ft.icons.BOOKMARK_BORDER,
selected_icon=ft.icons.BOOKMARK,
label="Explore",
),
],
)
page.add(content)
ft.app(target=main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment