flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
10.91k stars 420 forks source link

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

Closed PhunkyBob closed 1 week ago

PhunkyBob commented 2 months ago

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 ```python 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 ```python 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) ```
ndonkoHenri commented 1 week ago

Closing this issue in favor of https://github.com/flet-dev/flet/issues/3867

Please mention any further details in there.