flet icon indicating copy to clipboard operation
flet copied to clipboard

Add `*Destination.page_controls` property to ease Navigation

Open ndonkoHenri opened this issue 3 months ago • 2 comments

Description

*Destination.page_controls is a list of controls to be displayed in the page when a destination is clicked. It functions by simply replacing the current page.controls by the provided page_controls, provided page_controls is not None..

Test code

import flet as ft


def main(page: ft.Page):
    page.window_always_on_top = True
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
    page.vertical_alignment = ft.MainAxisAlignment.CENTER
    page.navigation_bar = ft.NavigationBar(
        on_change=lambda _: None,  # callback must be provided - can we make it work without?
        selected_index=1,
        destinations=[
            ft.NavigationDestination(
                icon=ft.icons.EXPLORE,
                label="Explore",
                page_controls=[ft.Text("Explore")],
            ),
            ft.NavigationDestination(
                icon=ft.icons.COMMUTE,
                label="Commute",
                page_controls=[ft.Text("Commute")],
            ),
            ft.NavigationDestination(
                icon=ft.icons.BOOKMARK_BORDER,
                selected_icon=ft.icons.BOOKMARK,
                label="Explore",
                page_controls=[ft.Text("Bookmark")],
            ),
        ],
    )
    page.add(ft.Text("Commute"))


ft.app(target=main)

Enhancements

The current implementation works as expected... provided on_change callback is set. Without it being set, the page_controls won't be displayed when a destination is clicked.

Related Issue

Closes #3092

ndonkoHenri avatar May 17 '24 15:05 ndonkoHenri