|
1 | 1 | from dataclasses import field
|
2 |
| -from typing import List, Optional |
| 2 | +from typing import Optional |
3 | 3 |
|
4 | 4 | from flet.controls.animation import Animation, AnimationCurve
|
5 | 5 | from flet.controls.base_control import control
|
6 | 6 | from flet.controls.control import Control
|
7 | 7 | from flet.controls.dialog_control import DialogControl
|
8 |
| - |
9 | 8 | from flet.controls.duration import Duration
|
10 |
| - |
11 | 9 | from flet.controls.types import StrOrControl
|
12 | 10 |
|
13 | 11 | __all__ = ["CupertinoAlertDialog"]
|
|
17 | 15 | class CupertinoAlertDialog(DialogControl):
|
18 | 16 | """
|
19 | 17 | An iOS-style alert dialog.
|
20 |
| - An alert dialog informs the user about situations that require acknowledgement. An alert dialog has an optional title and an optional list of actions. The title is displayed above the content and the actions are displayed below the content. |
21 |
| -
|
22 |
| - Example: |
23 |
| - ``` |
24 |
| - import flet as ft |
25 |
| -
|
26 |
| -
|
27 |
| - def main(page: ft.Page): |
28 |
| - page.horizontal_alignment = ft.CrossAxisAlignment.CENTER |
29 |
| - page.scroll = True |
30 |
| -
|
31 |
| - def handle_action_click(e): |
32 |
| - page.add(ft.Text(f"Action clicked: {e.control.text}")) |
33 |
| - # e.control is the clicked action button, e.control.parent is the corresponding parent dialog of the button |
34 |
| - page.close(e.control.parent) |
35 |
| -
|
36 |
| - cupertino_actions = [ |
37 |
| - ft.CupertinoDialogAction( |
38 |
| - "Yes", |
39 |
| - is_destructive_action=True, |
40 |
| - on_click=handle_action_click, |
41 |
| - ), |
42 |
| - ft.CupertinoDialogAction( |
43 |
| - text="No", |
44 |
| - is_default_action=False, |
45 |
| - on_click=handle_action_click, |
46 |
| - ), |
47 |
| - ] |
48 |
| -
|
49 |
| - material_actions = [ |
50 |
| - ft.TextButton(text="Yes", on_click=handle_action_click), |
51 |
| - ft.TextButton(text="No", on_click=handle_action_click), |
52 |
| - ] |
53 |
| -
|
54 |
| - page.add( |
55 |
| - ft.FilledButton( |
56 |
| - text="Open Material Dialog", |
57 |
| - on_click=lambda e: page.open( |
58 |
| - ft.AlertDialog( |
59 |
| - title=ft.Text("Material Alert Dialog"), |
60 |
| - content=ft.Text("Do you want to delete this file?"), |
61 |
| - actions=material_actions, |
62 |
| - ) |
63 |
| - ), |
64 |
| - ), |
65 |
| - ft.CupertinoFilledButton( |
66 |
| - text="Open Cupertino Dialog", |
67 |
| - on_click=lambda e: page.open( |
68 |
| - ft.CupertinoAlertDialog( |
69 |
| - title=ft.Text("Cupertino Alert Dialog"), |
70 |
| - content=ft.Text("Do you want to delete this file?"), |
71 |
| - actions=cupertino_actions, |
72 |
| - ) |
73 |
| - ), |
74 |
| - ), |
75 |
| - ft.FilledButton( |
76 |
| - text="Open Adaptive Dialog", |
77 |
| - adaptive=True, |
78 |
| - on_click=lambda e: page.open( |
79 |
| - ft.AlertDialog( |
80 |
| - adaptive=True, |
81 |
| - title=ft.Text("Adaptive Alert Dialog"), |
82 |
| - content=ft.Text("Do you want to delete this file?"), |
83 |
| - actions=cupertino_actions if page.platform in [ft.PagePlatform.IOS, ft.PagePlatform.MACOS] else material_actions, |
84 |
| - ) |
85 |
| - ), |
86 |
| - ), |
87 |
| - ) |
88 | 18 |
|
89 |
| -
|
90 |
| - ft.app(target=main) |
91 |
| - ``` |
92 |
| - ----- |
| 19 | + An alert dialog informs the user about situations that require acknowledgement. An |
| 20 | + alert dialog has an optional title and an optional list of actions. The title is |
| 21 | + displayed above the content and the actions are displayed below the content. |
93 | 22 |
|
94 | 23 | Online docs: https://flet.dev/docs/controls/cupertinoalertdialog
|
95 | 24 | """
|
96 | 25 |
|
97 | 26 | modal: bool = False
|
| 27 | + """ |
| 28 | + If set to True, dialog cannot be dismissed by clicking the area outside of it. |
| 29 | + The default value is False. |
| 30 | + """ |
| 31 | + |
98 | 32 | title: Optional[StrOrControl] = None
|
| 33 | + """ |
| 34 | + The (optional) title of the dialog is displayed in a large font at the top of the |
| 35 | + dialog. |
| 36 | +
|
| 37 | + Typically a [`Text`](https://flet.dev/docs/controls/text) control. |
| 38 | + """ |
| 39 | + |
99 | 40 | content: Optional[Control] = None
|
100 |
| - actions: List[Control] = field(default_factory=list) |
| 41 | + """ |
| 42 | + The (optional) content of the dialog is displayed in the center of the dialog in a |
| 43 | + lighter font. |
| 44 | +
|
| 45 | + Typically this is a [`Column`](https://flet.dev/docs/controls/column) that contains |
| 46 | + the dialog's [`Text`](https://flet.dev/docs/controls/text) message. |
| 47 | + """ |
| 48 | + |
| 49 | + actions: list[Control] = field(default_factory=list) |
| 50 | + """ |
| 51 | + The (optional) set of actions that are displayed at the bottom of the dialog. |
| 52 | +
|
| 53 | + Typically this is a list of |
| 54 | + [`CupertinoDialogAction`](https://flet.dev/docs/controls/cupertinodialogaction) |
| 55 | + controls. |
| 56 | + """ |
| 57 | + |
101 | 58 | inset_animation: Animation = field(
|
102 | 59 | default_factory=lambda: Animation(
|
103 | 60 | curve=AnimationCurve.DECELERATE, duration=Duration(milliseconds=100)
|
104 | 61 | )
|
105 | 62 | )
|
| 63 | + """ |
| 64 | + The animation style to be used when the system keyboard intrudes into the space |
| 65 | + that the dialog is placed in. |
| 66 | +
|
| 67 | + Value is of type |
| 68 | + [`AnimationStyle`](https://flet.dev/docs/reference/types/animationstyle). |
| 69 | + """ |
106 | 70 |
|
107 | 71 | def before_update(self):
|
108 | 72 | super().before_update()
|
109 | 73 | assert (
|
110 | 74 | (isinstance(self.title, str) or self.title.visible)
|
111 | 75 | or (self.content and self.content.visible)
|
112 | 76 | or any(a.visible for a in self.actions)
|
113 |
| - ), "AlertDialog has nothing to display. Provide at minimum one of the following: title, content, actions" |
| 77 | + ), "AlertDialog has nothing to display. Provide at minimum one of the " |
| 78 | + "following: title, content, actions" |
0 commit comments