#๐Ÿ”’ Flet app not displaying views

6 messages ยท Page 1 of 1 (latest)

undone vale
#

I'm following along with a flet tutorial and run into an issue with the Page not displaying the Views I've defined:

import flet as ft
from flet import (
    View,
    Page,
    AppBar,
    ElevatedButton,
    Text,
    RouteChangeEvent,
    CrossAxisAlignment,
    MainAxisAlignment,
    ViewPopEvent,
)


def main(page: Page) -> None:
    page.title = "My Store"

    def route_change(e: RouteChangeEvent) -> None:
        page.views.clear()

        page.views.append(
            View(
                route="/",
                controls=[
                    AppBar(title=Text("Home"), bgcolor="Blue"),
                    Text(value="Home", size=30),
                    ElevatedButton(
                        text="Go to Store", on_click=lambda _: page.go("/store")
                    ),
                ],
                vertical_alignment=MainAxisAlignment.CENTER,
                horizontal_alignment=CrossAxisAlignment.CENTER,
                spacing=26,
            )
        )

        if page.route == "/store":
            page.views.append(
                View(
                    route="/store",
                    controls=[
                        AppBar(title=Text("Store"), bgcolor="Blue"),
                        Text(value="Store", size=30),
                        ElevatedButton(text="Go Back", on_click=lambda _: page.go("/")),
                    ],
                    vertical_alignment=MainAxisAlignment.CENTER,
                    horizontal_alignment=CrossAxisAlignment.CENTER,
                    spacing=26,
                )
            )

    def view_pop(e: ViewPopEvent) -> None:
        page.views.pop()
        top_view = page.views[-1]
        page.go(top_view.route)

    page.on_route_change = route_change
    page.on_view_pop = view_pop
    page.go("/")


ft.app(main)

The resulting window is blank, rather than displaying the view for the root route

vivid barnBOT
#

@undone vale

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

undone vale
#

Figured it out, adding a call to page.update() at the end of the route_change function fixes the issue

#

!close

vivid barnBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.