Skip to content

CupertinoAlertDialog

Examples#

Live example

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)

file-deletion-confirmation

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 #

actions: list[Control] = field(default_factory=list)

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.

badge #

badge: BadgeValue | None = None

A badge to show on top of this control.

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

content #

content: Control | None = None

The (optional) content of the dialog is displayed in the center of the dialog in a lighter font.

Typically this is a Column that contains the dialog's Text message.

data #

data: Any = skip_field()

Arbitrary data of any type.

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.

Example

For example, if you have a form with multiple entry controls you can disable them all together by disabling container:

ft.Column(
    disabled = True,
    controls=[
        ft.TextField(),
        ft.TextField()
    ]
)

expand #

expand: bool | int | None = None

Specifies whether/how this control should expand to fill available space in its parent layout.

More information here.

Note

Has effect only if the direct parent of this control is one of the following controls, or their subclasses: Column, Row, View, Page.

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.

Note

If expand_loose is True, it will have effect only if:

  • expand is not None and
  • the direct parent of this control is one of the following controls, or their subclasses: Column, Row, View, Page.

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.

key #

key: (
    str | int | float | bool | ValueKey | ScrollKey | None
) = None

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).

open #

open: bool = False

Set to True to display this dialog.

page #

page: Page | PageView | None

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.

rtl #

rtl: bool = False

Whether the text direction of the control should be right-to-left (RTL).

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.

before_event #

before_event(e: ControlEvent)

before_update #

before_update()

clean #

clean() -> None

did_mount #

did_mount()

init #

init()

is_isolated #

is_isolated()

update #

update() -> None

will_unmount #

will_unmount()