Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

NavigationRail is not shown if expand=True of parent is set in build method #1810

Closed
vodjan opened this issue Sep 6, 2023 · 0 comments
Closed

Comments

@vodjan
Copy link

vodjan commented Sep 6, 2023

I hereby solemnly swear that I have read #287 and #303 and that what I am describing is, to my understanding, not covered by the solutions provided therein.

The following code results in an error, even though I am using a Row with expand=True to restrict the NavigationRail's height, as recommended in #303:

import flet as ft


class AppView(ft.UserControl):
    def __init__(self):
        super().__init__()
        self.navigation_rail = ft.NavigationRail(
            destinations=[
                ft.NavigationRailDestination(
                    icon=ft.icons.START,
                    label="one destination"
                ),
                ft.NavigationRailDestination(
                    icon=ft.icons.STAR,
                    label="another destination"
                )
            ],
            on_change=lambda event: print("Selected destination:", event.control.selected_index),
        )

    def build(self):
        return ft.Row(
            controls=[
                self.navigation_rail
            ],
            expand=True
        )


def main(page: ft.Page):
    app_view = AppView()
    page.add(app_view)


ft.app(target=main)

However, when I change main to wrap the NavigationRail in a Row with expand=True, the code works: both

def main(page: ft.Page):
    app_view = AppView()
    page.add(ft.Row([app_view], expand=True))

and

def main(page: ft.Page):
    app_view = AppView()
    page.add(ft.Row([app_view.navigation_rail], expand=True))

work just fine. These also work if I replace expand=True with height=200 in main.

Using an explicit height restriction in the build method also works fine, i.e.

class AppView(ft.UserControl):

...

    def build(self):
        return ft.Row(
            controls=[
                self.navigation_rail
            ],
            height=200
        )


def main(page: ft.Page):
    app_view = AppView()
    page.add(app_view)


ft.app(target=main)
@flet-dev flet-dev locked and limited conversation to collaborators Sep 6, 2023
@FeodorFitsner FeodorFitsner converted this issue into discussion #1811 Sep 6, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant