-
Notifications
You must be signed in to change notification settings - Fork 645
Expand file tree
/
Copy pathuse_dialog_basic.py
More file actions
56 lines (48 loc) · 1.45 KB
/
use_dialog_basic.py
File metadata and controls
56 lines (48 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import asyncio
import flet as ft
@ft.component
def App():
show, set_show = ft.use_state(False)
deleting, set_deleting = ft.use_state(False)
async def handle_delete():
set_deleting(True)
# Simulate async operation
await asyncio.sleep(2)
set_deleting(False)
set_show(False)
ft.use_dialog(
ft.AlertDialog(
modal=True,
title=ft.Text("Delete report.pdf?"),
content=ft.Text(
"Deleting, please wait..." if deleting else "This cannot be undone."
),
actions=[
ft.Button(
"Deleting..." if deleting else "Delete",
disabled=deleting,
on_click=handle_delete,
),
ft.TextButton(
"Cancel",
on_click=lambda: set_show(False),
disabled=deleting,
),
],
on_dismiss=lambda: set_show(False),
)
if show
else None
)
return ft.Column(
controls=[
ft.Text("Declarative Dialog Example", size=24, weight=ft.FontWeight.BOLD),
ft.Text("Click the button to open a confirmation dialog."),
ft.Button(
"Delete File",
icon=ft.Icons.DELETE,
on_click=lambda: set_show(True),
),
],
)
ft.run(lambda page: page.render(App))