flet icon indicating copy to clipboard operation
flet copied to clipboard

Inconsistent Control behavior on Android: work in dev, malfunction when packaged

Open tanmay-bhatgare opened this issue 1 year ago • 5 comments

Duplicate Check

  • [x] I have searched the opened issues and there are no duplicates

Describe the bug

After packaging app into .apk some of the app widgets misbehave mostly ones containing dialogues or pop ups. These all window work great in development mode but don't know why they just don't open in real android device, tried every way and didn't work any of them, this behavior is also shown by widgets containing images stored locally. eg. container etc. See this, #3866

Code sample

Code
import flet as ft


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

    dlg = ft.AlertDialog(
        title=ft.Text("Hi, this is a non-modal dialog!"),
        on_dismiss=lambda e: page.add(ft.Text("Non-modal dialog dismissed")),
    )

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

    dlg_modal = ft.AlertDialog(
        modal=True,
        title=ft.Text("Please confirm"),
        content=ft.Text("Do you really want to delete all those files?"),
        actions=[
            ft.TextButton("Yes", on_click=handle_close),
            ft.TextButton("No", on_click=handle_close),
        ],
        actions_alignment=ft.MainAxisAlignment.END,
        on_dismiss=lambda e: page.add(
            ft.Text("Modal dialog dismissed"),
        ),
    )

    page.add(
        ft.ElevatedButton("Open dialog", on_click=lambda e: page.open(dlg)),
        ft.ElevatedButton("Open modal dialog", on_click=lambda e: page.open(dlg_modal)),
    )


ft.app(target=main)

To reproduce

  1. Build a apk using flet build apk.
  2. Open the app and press the button nothing will work neither crash.

Expected behavior

In real android device all the widget should behave as expected but widgets containing dialogues or pop up don't even respond or open and don't throw any error or info.

Screenshots / Videos

Captures

[Upload media here]

Operating System

Windows

Operating system details

windows 11

Flet version

0.23.2

Regression

No, it isn't

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

tanmay-bhatgare avatar Aug 25 '24 05:08 tanmay-bhatgare

Similar issues (concerning the inconsistency) were reported:

  • https://github.com/flet-dev/flet/issues/3664
  • https://github.com/flet-dev/flet/issues/3461
  • https://github.com/flet-dev/flet-lottie/issues/12
  • https://github.com/flet-dev/flet/issues/2900

ndonkoHenri avatar Aug 25 '24 14:08 ndonkoHenri

As I mentioned in my issue (#3951), if deprecated approach is used (like pick_time() in TimePicker) and element is added using Page.overlay.append(...) everything works like expected.

Maybe this will be helpful to future changes or just for library users, who want their control elements behave normally in current versions.

DanyaIzm avatar Sep 08 '24 11:09 DanyaIzm

@DanyaIzm I have tried your approach and it work, thought it will only work for DatePicker and TimePicker but it worked for every pop-up widget after packaging into .apk.

import datetime
import flet as ft


def main(page: ft.Page):
    page.title = "Date Picker"

    def open_date_picker(e, date_picker: ft.DatePicker):
        date_picker.pick_date()

    def handle_confirm_click(e):
        date_text.value = date_picker.value.strftime("%d/%m/%Y")
        page.update()

    def open_dialog(e):
        dialog.open = True
        page.update()

    dialog = ft.AlertDialog(
        title=ft.Text("Dialog Box"),
        content=ft.Text("This is a sample dialog."),
        actions=[ft.TextButton("Close", on_click=lambda e: close_dialog(e))],
    )

    def close_dialog(e):
        dialog.open = False
        page.update()

    date_picker = ft.DatePicker(
        value=datetime.datetime.now(),
        first_date=datetime.datetime.now(),
        last_date=datetime.datetime.now() + datetime.timedelta(days=365 * 10),
        confirm_text="Confirm",
        error_invalid_text="Date out of range",
        help_text="Pick your Date slot",
        on_change=handle_confirm_click,
    )

    date_button = ft.ElevatedButton(
        text="Pick A Date",
        on_click=lambda e: open_date_picker(e, date_picker=date_picker),
    )

    dialog_button = ft.ElevatedButton(
        text="Open Dialog",
        on_click=open_dialog,
    )

    date_text = ft.Text(value="", color="purple")

    page.overlay.append(date_picker)
    page.overlay.append(dialog)

    page.add(
        ft.Row(
            [
                ft.Column(
                    [
                        date_button,
                        dialog_button,
                        date_text,
                    ],
                    alignment=ft.MainAxisAlignment.CENTER,
                    horizontal_alignment=ft.CrossAxisAlignment.CENTER,
                )
            ],
            expand=True,
            alignment=ft.MainAxisAlignment.CENTER,
            vertical_alignment=ft.CrossAxisAlignment.CENTER,
        )
    )


ft.app(main)

I tried every other widget but build apk for only these two as the are often used. This is the result.

https://github.com/user-attachments/assets/5cba085a-d6ff-4974-9cae-95797e73f95a

tanmay-bhatgare avatar Sep 08 '24 14:09 tanmay-bhatgare

@ndonkoHenri please can you tell me why you reopened this issue?😅

tanmay-bhatgare avatar Sep 08 '24 17:09 tanmay-bhatgare

Issue needs to be well addressed.

ndonkoHenri avatar Sep 08 '24 18:09 ndonkoHenri

For all of you facing this issue ("work in dev, malfunction when packaged"), please give the Flet prerelease a try and provide feedback.

pip install flet --pre -U

Make sure to change the version of Flet in your requirements to a prerelease version (ex: flet==0.25.0.dev3526) before packaging.

ndonkoHenri avatar Nov 02 '24 14:11 ndonkoHenri

For all of you facing this issue ("work in dev, malfunction when packaged"), please give the Flet prerelease a try and provide feedback.Will inform if found other bugs related packaging.

pip install flet --pre -UWill inform if found other bugs related packaging.

Make sure to change the version of Flet in your requirements to a prerelease version (ex: flet==0.25.0.dev3526) before packaging.

@ndonkoHenri I tried new flet pre-packaging but for quick development I used Google IDX, and it was quite good, but still have some bugs. I tried same code to pack into apk, for which this issue was raised. The flet controls now behave perfectly fine and work as they are intended to. Now regarding packaging I only faced 1 bug which is related to app icon, while packaging everything ran flawlessly but when I installed the packed app on my both Vivo and Oppo device, it got installed but with no icon, literally without an icon. I thought I messed with files tho i set assets_dir="assets" so don't think it was file structure error. It didn't even show me in terminal as a warning or error. Will inform if found other bugs related packaging. Quick question: should I raise issue regarding no icon after packaging?

Better file structure for easy debugging:

  1. build/app/app.zip: for better understanding of what has packed as apk.
  2. build/flutter/: for query of entire app's flutter codebase. Screenshot 2024-11-02 225336

Bugs Found

  1. Application got packed without Icon

tanmay-bhatgare avatar Nov 02 '24 18:11 tanmay-bhatgare

@tanmay-bhatgare thanks for giving it a try, happy to know it works.

Concerning the icon we have an opened issue for it: https://github.com/flet-dev/flet/issues/4244 It has been fixed but not yet merged.

ndonkoHenri avatar Nov 02 '24 20:11 ndonkoHenri