-
Notifications
You must be signed in to change notification settings - Fork 584
Description
Description
It seems that on_window_event
doesn't trigger after navigating to a new view.
It seems to be a regression - on version 0.10.3 it works, but breaks on 0.12.0.
Code example to reproduce the issue:
import flet as ft
def main(page: ft.Page):
page.title = "Routes Example"
def route_change(route):
page.views.clear()
page.views.append(
ft.View(
"/",
[
ft.AppBar(title=ft.Text("Flet app"), bgcolor=ft.colors.SURFACE_VARIANT),
ft.ElevatedButton("Visit Store", on_click=lambda _: page.go("/store")),
],
)
)
if page.route == "/store":
page.views.append(
ft.View(
"/store",
[
ft.AppBar(title=ft.Text("Store"), bgcolor=ft.colors.SURFACE_VARIANT),
ft.ElevatedButton("Go Home", on_click=lambda _: page.go("/")),
],
)
)
page.update()
def view_pop(view):
page.views.pop()
top_view = page.views[-1]
page.go(top_view.route)
def window_event(e):
print(f"window event: {e}")
if e.data == "close":
page.window_destroy()
page.window_prevent_close = True
page.on_window_event = window_event
page.on_route_change = route_change
page.on_view_pop = view_pop
page.go(page.route)
if __name__ == '__main__':
ft.app(target=main)
Describe the results you received:
Original view allows to exit, but once a new view is appeneded then the window X exit button has no effect and doesnt trigger the on_window_event
func.
Navigating back to the home view unblocks the exit button.
Describe the results you expected:
Exit should work regardless of view added.
Additional information you deem important (e.g. issue happens only occasionally):
Version 0.10.3 doesn't have this issue
Flet version (pip show flet
):
0.12.0
Operating system:
Reproduced on macos + windows 10
Additional environment details: