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