CupertinoAlertDialog
Examples#
File deletion confirmation#
import flet as ft
def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
def handle_dialog_dismissal(e: ft.Event[ft.CupertinoAlertDialog]):
page.add(ft.Text("Dialog dismissed"))
def handle_action_click(e: ft.Event[ft.CupertinoDialogAction]):
page.add(ft.Text(f"Action clicked: {e.control.content}"))
page.pop_dialog()
cupertino_alert_dialog = ft.CupertinoAlertDialog(
title=ft.Text("Cupertino Alert Dialog"),
content=ft.Text("Do you want to delete this file?"),
on_dismiss=handle_dialog_dismissal,
actions=[
ft.CupertinoDialogAction(
content="Yes",
destructive=True,
on_click=handle_action_click,
),
ft.CupertinoDialogAction(
content="No", default=True, on_click=handle_action_click
),
],
)
page.add(
ft.CupertinoFilledButton(
content="Open CupertinoAlertDialog",
on_click=lambda e: page.show_dialog(cupertino_alert_dialog),
)
)
ft.run(main)
Cupertino, material and adaptive alert dialogs#
from typing import Union
import flet as ft
def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.scroll = ft.ScrollMode.AUTO
def handle_action_click(
e: ft.Event[Union[ft.TextButton, ft.CupertinoDialogAction]],
):
page.add(ft.Text(f"Action clicked: {e.control.content}"))
page.pop_dialog()
cupertino_actions = [
ft.CupertinoDialogAction(
content="Yes",
destructive=True,
on_click=handle_action_click,
),
ft.CupertinoDialogAction(
content="No",
default=False,
on_click=handle_action_click,
),
]
material_actions = [
ft.TextButton(content="Yes", on_click=handle_action_click),
ft.TextButton(content="No", on_click=handle_action_click),
]
page.add(
ft.FilledButton(
content="Open Material Dialog",
on_click=lambda e: page.show_dialog(
ft.AlertDialog(
title=ft.Text("Material Alert Dialog"),
content=ft.Text("Do you want to delete this file?"),
actions=material_actions,
)
),
),
ft.CupertinoFilledButton(
content="Open Cupertino Dialog",
on_click=lambda e: page.show_dialog(
ft.CupertinoAlertDialog(
title=ft.Text("Cupertino Alert Dialog"),
content=ft.Text("Do you want to delete this file?"),
actions=cupertino_actions,
)
),
),
ft.FilledButton(
content="Open Adaptive Dialog",
adaptive=True,
bgcolor=ft.Colors.BLUE_ACCENT,
on_click=lambda e: page.show_dialog(
ft.AlertDialog(
adaptive=True,
title=ft.Text("Adaptive Alert Dialog"),
content=ft.Text("Do you want to delete this file?"),
actions=(
cupertino_actions
if page.platform.is_apple()
else material_actions
),
)
),
),
)
ft.run(main)
CupertinoAlertDialog
#
Bases: DialogControl
An iOS-style alert dialog.
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.
actions
#
The (optional) set of actions that are displayed at the bottom of the dialog.
Typically this is a list of
CupertinoDialogAction
controls.
adaptive
#
adaptive: bool | None = None
Enables platform-specific rendering or inheritance of adaptiveness from parent controls.
col
#
col: ResponsiveNumber = 12
If a parent of this control is a ResponsiveRow
,
this property is used to determine
how many virtual columns of a screen this control will span.
Can be a number or a dictionary configured to have a different value for specific
breakpoints, for example col={"sm": 6}
.
This control spans the 12 virtual columns by default.
Dimensions
Breakpoint | Dimension |
---|---|
xs | <576px |
sm | ≥576px |
md | ≥768px |
lg | ≥992px |
xl | ≥1200px |
xxl | ≥1400px |
disabled
#
disabled: bool = False
Every control has disabled
property which is False
by default - control and all
its children are enabled.
Note
The value of this property will be propagated down to all children controls recursively.
expand
#
expand_loose
#
expand_loose: bool = False
Allows the control to expand along the main axis if space is available, but does not require it to fill all available space.
More information here.
inset_animation
#
inset_animation: Animation = field(
default_factory=lambda: Animation(
curve=DECELERATE,
duration=Duration(milliseconds=100),
)
)
The animation style to be used when the system keyboard intrudes into the space that the dialog is placed in.
modal
#
modal: bool = False
Whether this dialog cannot be dismissed by clicking the area outside of it.
on_dismiss
#
on_dismiss: ControlEventHandler[DialogControl] | None = None
Called when dialog is dismissed.
opacity
#
opacity: Number = 1.0
Defines the transparency of the control.
Value ranges from 0.0
(completely transparent) to 1.0
(completely opaque
without any transparency).
page
#
The page (of type Page
or PageView
) to which this control belongs to.
parent
#
parent: BaseControl | None
The direct ancestor(parent) of this control.
It defaults to None
and will only have a value when this control is mounted (added to the page tree).
The Page
control (which is the root of the tree) is an exception - it always has parent=None
.
title
#
title: StrOrControl | None = None
The (optional) title of the dialog is displayed in a large font at the top of the dialog.
Typically a Text
control.
tooltip
#
tooltip: TooltipValue | None = None
The tooltip ot show when this control is hovered over.
visible
#
visible: bool = True
Every control has visible
property which is True
by default - control is
rendered on the page. Setting visible
to False
completely prevents control (and
all its children if any) from rendering on a page canvas. Hidden controls cannot be
focused or selected with a keyboard or mouse and they do not emit any events.