Skip to content

page.open(ft.AlertDialog) and .close don't work as expected on Android #3664

Description

@PhunkyBob

Duplicate Check

Describe the bug

When I want to display an AlertDialog with page.open( ), it works on Windows and with flet run --android, but not on Android once installed with an APK.

Code sample

Code
import flet as ft


def main(page: ft.Page):
    page.title = "AlertDialog examples"
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    def handle_close(e):
        page.close(dlg_modal)
        page.add(ft.Text(f"Modal dialog closed with action: {e.control.text}"))

    def handle_dismiss(e):
        page.add(ft.Text("Modal dialog dismissed"))

    def handle_click(e):
        page.open(dlg_modal)

    dlg_modal = ft.AlertDialog(
        modal=True,
        title=ft.Text("Please confirm"),
        content=ft.Text("Do you really want to ...?"),
        actions=[
            ft.TextButton("Yes", on_click=handle_close),
            ft.TextButton("No", on_click=handle_close),
        ],
        actions_alignment=ft.MainAxisAlignment.END,
        on_dismiss=handle_dismiss,
    )

    page.add(
        ft.Text("This is a simple example of an AlertDialog."),
        ft.ElevatedButton("Open modal dialog", on_click=handle_click),
    )


ft.app(target=main)

To reproduce

  1. Create a file test.py with the previous content.
  2. Create an APK with flet build apk --module-name test.py.
  3. Install APK on Android.
  4. Run application on Android device.
  5. Tap on the "Open modal dialog" button.

Expected behavior

I expect to have an alert dialog.

Screenshots / Videos

No screenshot

Operating System

Windows

Operating system details

Windows 11 / Android 13

Flet version

0.23.2

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

No logs

Additional details

As a workaround, I add the AlertDialog to the page and use .open property of AlertDialog:

Code
import flet as ft


def main(page: ft.Page):
    page.title = "AlertDialog examples"
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    def handle_close(e):
        dlg_modal.open = False
        page.add(ft.Text(f"Modal dialog closed with action: {e.control.text}"))

    def handle_dismiss(e):
        page.add(ft.Text("Modal dialog dismissed"))

    def handle_click(e):
        dlg_modal.open = True
        page.add(ft.Text(f"Modal dialog opened with action: {e.control.text}"))

    dlg_modal = ft.AlertDialog(
        modal=True,
        title=ft.Text("Please confirm"),
        content=ft.Text("Do you really want to ...?"),
        actions=[
            ft.TextButton("Yes", on_click=handle_close),
            ft.TextButton("No", on_click=handle_close),
        ],
        actions_alignment=ft.MainAxisAlignment.END,
        on_dismiss=handle_dismiss,
    )

    page.add(
        dlg_modal,
        ft.Text("This is a simple example of an AlertDialog."),
        ft.ElevatedButton("Open modal dialog", on_click=handle_click),
    )


ft.app(target=main)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackagingRelated to app packagingplatform: androidSpecific to Android

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions