[Question] In Navigation and Routing, how to use AlertDialog? #3077
-
QuestionI want to open ft.AlertDialog(dlg) when I click <ElevatedButton("Open Dlg")> in /store. please help me!!! Code sampleimport flet as ft
import time
def main(page: ft.Page):
page.title = "Navigation and Routing and AlertDialog examples"
def open_dlg(e):
page.dialog = dlg
dlg.open = True
page.update
time.sleep(5)
dlg.open = False
page.update()
dlg = ft.AlertDialog(
title=ft.Text("Hello, you!"), on_dismiss=lambda e: print("Dialog dismissed!"),
)
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")),
# ft.ElevatedButton("Open Dlg", on_click=open_dlg),
],
)
)
if page.route == "/store":
page.views.append(
ft.View(
"/store",
[
ft.AppBar(title=ft.Text("Store"), bgcolor=ft.colors.SURFACE_VARIANT),
ft.ElevatedButton("Open Dlg", on_click=open_dlg),
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)
page.on_route_change = route_change
page.on_view_pop = view_pop
page.go(page.route)
ft.app(target=main, host = "192.168.35.35", port = 8550, view=ft.AppView.WEB_BROWSER)
# ft.app(target=main, host = "192.168.35.35", port = 8550, view=ft.WEB_BROWSER) Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Answered by
abdokhalil07
Apr 22, 2024
Replies: 1 comment 2 replies
-
import flet as ft def main(page: ft.Page):
ft.app(target=main, port = 8550, view=ft.AppView.WEB_BROWSER) ft.app(target=main, host = "192.168.35.35", port = 8550, view=ft.WEB_BROWSER) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dont make open and close dialog in the same function
write to open dialog function and close dialog function
and call close_dialog from open_dialog