flet icon indicating copy to clipboard operation
flet copied to clipboard

Problem with the new pypi flet_permission_handler in 0.26.0.

Open SIRGPrice opened this issue 1 year ago • 13 comments

Duplicate Check

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

Describe the bug

I replicated the steps of the docs and 0.26.0 blog to install, copy-paste code (adapting to the context), run and make apk process.

No problem with anything until apk done, no error in any file or process until apk is done with success.

When I try the apk app in the phone, a white page opens and raises an error: No module named flet_permission_handler.

I think the problem is that once apk is done, flutter dart files related with flet_permission_handler dont recognice the imports and thats because once apk is done mi pubspec.yaml looks like this in the lines related with the flet_permission_handler:

dependencies: cupertino_icons: ^1.0.6 flet_permission_handler: path: C:\Users*user*\Desktop*appname*\build\flutter-packages\flet_permission_handler flutter: sdk: flutter package_info_plus: ^8.0.2 path: ^1.9.0 path_provider: ^2.1.4 serious_python: 0.8.7 url_strategy: ^0.2.0 window_manager: ^0.4.3

The path of the module is a windows path that references the proyect folder where the flet_permission_handler dart files are located (the ones that give errors in their imports).

So when I try flet run --android it works perfectly in the play store flet app for emulation, because the app is really runing in my computer and it can access the path and open the android settings at the same time.

But when apk done the yaml cannot redirect to anywhere because in my mobile that path does not exist.

How can I solve it? Thanks.

Code sample

Code

.yaml ->

dependencies:
  cupertino_icons: ^1.0.6
  flet_permission_handler:
    path: C:\Users\x\Desktop\y\build\flutter-packages\flet_permission_handler
  flutter:
    sdk: flutter
  package_info_plus: ^8.0.2
  path: ^1.9.0
  path_provider: ^2.1.4
  serious_python: 0.8.7
  url_strategy: ^0.2.0
  window_manager: ^0.4.3

.toml ->

...
[tool.poetry.dependencies]
python = "^3.10.4"
flet = "^0.26.0"
pywifi = "^1.1.12"
websockets = "^12.0"
numpy = "^1.26.4"
flet-permission-handler = "^0.1.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.android.permission]
"android.permission.NEARBY_WIFI_DEVICES" = true

To reproduce

https://pypi.org/project/flet-permission-handler/ https://flet.dev/docs/controls/permissionhandler/

Expected behavior

Open android settings

Screenshots / Videos

Captures

[Upload media here]

Operating System

windows 11

Operating system details

None

Flet version

0.26.0

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

I tryed with flet build apk and flet build apk --include-packages flet_permission_handler. I tryed the 3º party asociated module and the same happends.

SIRGPrice avatar Feb 06 '25 13:02 SIRGPrice

No need to use --include-packages or tweak pubspec.yaml anymore.

flet-permission-handler dependency should be added to pyproject.toml.

Build with flet build apk -v and paste the log here.

FeodorFitsner avatar Feb 06 '25 16:02 FeodorFitsner

Thanks Feodor.

The same happends with flet build apk -v. Log here:

[18:02:06] Run subprocess: ['C:\Users\tonch\flutter\bin\flutter.BAT', '--version', '--no-version-check', '--suppress-analytics']
Flutter executable: C:\Users\tonch\flutter\bin\flutter.BAT Dart executable: C:\Users\tonch\flutter\bin\dart.BAT JDK installed at C:\Users\tonch\java\17.0.13+11 Configuring Flutter's path to JDK
Run subprocess: ['C:\Users\tonch\flutter\bin\flutter.BAT', 'config', '--suppress-analytics', '--jdk-dir=C:\Users\tonch\java\17.0.13+11']
[18:02:08] Setting "jdk-dir" value to "C:\Users\tonch\java\17.0.13+11".

       You may need to restart any open editors for them to read new settings.
       JDK installed ✅                                                                                                                                                                                                  
       Android SDK installation found at C:\Users\tonch\AppData\Local\Android\Sdk
       Android SDK package "cmdline-tools;latest" is already installed
       Android SDK package "platform-tools" is already installed
       Android SDK package "platforms;android-35" is already installed
       Android SDK package "build-tools;34.0.0" is already installed
       Android SDK installed ✅                                                                                                                                                                                          
       Custom Flutter dependencies: {}                                                                                                                                                                                   

[18:02:12] Created Flutter bootstrap project from gh:flet-dev/flet-build-template with ref "0.26.0" ✅
Run subprocess: ['C:\Users\tonch\flutter\bin\dart.BAT', 'run', '--suppress-analytics', 'serious_python:main', 'package', 'C:\Users\tonch\Desktop\Batery', '--platform', 'Android', '--requirements',
'flet-permission-handler>=0.1.0,flet>=0.26.0,numpy>=1.26.4,pywifi>=1.1.12,websockets>=12.0', '--exclude', 'build', '--cleanup']
[18:03:41] Packaged Python app ✅
Found Flutter extension at C:\Users\tonch\Desktop\Batery\build\flutter-packages\flet_permission_handler
Registered Flutter user extensions ✅
[18:03:45] Copying C:\Users\tonch\Desktop\Batery\assets\icon.png to C:\Users\tonch\Desktop\Batery\build\flutter\images
Customized app icons and splash images ✅
Run subprocess: ['C:\Users\tonch\flutter\bin\dart.BAT', 'run', '--suppress-analytics', 'flutter_launcher_icons']
[18:03:47] ════════════════════════════════════════════ FLUTTER LAUNCHER ICONS (v0.14.3) ════════════════════════════════════════════

       • Creating default icons Android
       • Overwriting the default Android launcher icon with a new icon
       • Creating adaptive icons Android

[18:03:48] • Updating colors.xml with color for adaptive icon background • Creating mipmap xml file Android • Overwriting default iOS launcher icon with new icon [18:03:49] Creating Icons for Web... Creating Icons for Windows... Creating Icons for MacOS... [18:03:50] ✓ Successfully generated launcher icons Generated app icons ✅
Run subprocess: ['C:\Users\tonch\flutter\bin\dart.BAT', 'run', '--suppress-analytics', 'flutter_native_splash:create']
[18:03:52] [Android] Creating default splash images [Android] Creating dark mode splash images [Android] Creating default android12splash images [Android] Creating dark mode android12splash images [18:03:53] [Android] Updating launch background(s) with splash image path... [Android] - android/app/src/main/res/drawable/launch_background.xml [Android] - android/app/src/main/res/drawable-night/launch_background.xml [Android] - android/app/src/main/res/drawable-v21/launch_background.xml [Android] - android/app/src/main/res/drawable-night-v21/launch_background.xml [Android] Updating styles... [Android] - android/app/src/main/res/values-v31/styles.xml [Android] - android/app/src/main/res/values-night-v31/styles.xml [Android] - android/app/src/main/res/values/styles.xml [Android] - android/app/src/main/res/values-night/styles.xml Creating images Creating dark mode images Updating ios/Runner/Info.plist for status bar hidden/visible [18:03:54] [Web] Creating images [Web] Creating images [18:03:55] [Web] Creating background images [Web] Creating CSS [Web] Updating index.html

       ✅ Native splash complete.
       Now go finish building something awesome! 💪 You rock! 🤘🤩
       Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_native_splash

       Generated splash screens ✅                                                                                                                                                                                       
       Run subprocess: ['C:\\Users\\tonch\\flutter\\bin\\flutter.BAT', 'build', 'apk', '--no-version-check', '--suppress-analytics', '--build-name', '0.1.0']                                                            

[18:03:56] Resolving dependencies... [18:03:57] Downloading packages... archive 3.6.1 (4.0.2 available) characters 1.3.0 (1.4.0 available) clock 1.1.1 (1.1.2 available) collection 1.19.0 (1.19.1 available) fl_chart 0.69.2 (0.70.2 available) ! flet 0.26.0 (overridden) flutter_lints 2.0.3 (5.0.0 available) image 4.3.0 (4.5.2 available) intl 0.19.0 (0.20.2 available) js 0.6.7 (0.7.1 available) lints 2.1.1 (5.1.1 available) material_color_utilities 0.11.1 (0.12.0 available) meta 1.15.0 (1.16.0 available) path 1.9.0 (1.9.1 available) petitparser 6.0.2 (6.1.0 available) sensors_plus 4.0.2 (6.1.1 available) sensors_plus_platform_interface 1.2.0 (2.0.1 available) toml 0.15.0 (0.16.0 available) url_strategy 0.2.0 (discontinued) ! wakelock_plus 1.2.10 (overridden) ! web 1.1.0 (overridden) web_socket_channel 2.4.5 (3.0.2 available) ! webview_flutter_android 4.3.1 (overridden) win32_registry 1.1.5 (2.0.1 available) ! window_manager 0.4.3 (overridden) to 209160 bytes (18.8% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app. Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 1261080 bytes (23.3% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your
app. [18:06:12] Running Gradle task 'assembleRelease'... 133,7s [18:06:13] √ Built build\app\outputs\flutter-apk\app-release.apk (85.1MB) Built .apk for Android ✅
Copying build output from: C:\Users\tonch\Desktop\Batery\build\flutter\build\app\outputs\flutter-apk*
Copied build to build\apk directory ✅
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │ Successfully built your .apk for Android! 🥳 Find it in build\apk directory. 📁

SIRGPrice avatar Feb 06 '25 17:02 SIRGPrice

It looks good from the logs. What error are you getting when running the app on a phone? How do you import flet_permission_handler in the app?

FeodorFitsner avatar Feb 06 '25 18:02 FeodorFitsner

Im getting this error once opening my app in mobile:

Traceback (most recent call last): File "", line 95, in File "", line 229, in run_module File "", line 88, in _run_code File "/data/user/0/com.flet.xxxxxx/files/flet/app/main.py", line 17, in import flet_permission_handler as fph ModuleNotFoundError: No module named 'flet_permission_handler'

To import flet_permission_handler in the app I did:

In main.py: import flet_permission_handler as fph

In .toml in [tool.poetry.dependencies]: flet-permission-handler = "^0.1.0"

SIRGPrice avatar Feb 06 '25 18:02 SIRGPrice

OK, can you see what's inside .apk. Unpack .apk (it's a zip). Then inside archive locate lib/arm64-v8a/libpythonsitepackages.so and unpack it.

FeodorFitsner avatar Feb 06 '25 18:02 FeodorFitsner

lib/arm64-v8a/libpythonsitepackages.so:

Image

The 2 previously showed folders related with permission handler once opened:

Image

Image

SIRGPrice avatar Feb 06 '25 19:02 SIRGPrice

Edit your pyproject.toml into this and try to build your app

[project] requires-python = ">=3.10" dependencies = [ "flet-permission-handler==0.1.0", "flet==0.26.0", "pywifi== 1.1.12", "websockets==12.0", "numpy==1.26.4" ]

[build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"

[tool.poetry.android.permission] "android.permission.NEARBY_WIFI_DEVICES" = true

osamalzabidi avatar Feb 07 '25 21:02 osamalzabidi

Its not working.

I think I will try to enable permissions manually for a time and continue working in this issue.

If I can solve the problem you will be noticed here.

Thanks all mates.

SIRGPrice avatar Feb 10 '25 09:02 SIRGPrice

Edit your into this and try to build your apppyproject.toml

[project] requires-python = ">=3.10" dependencies = [ "flet-permission-handler==0.1.0", "flet==0.26.0", "pywifi== 1.1.12", "websockets==12.0", "numpy==1.26.4" ]

[build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"

[tool.poetry.android.permission] "android.permission.NEARBY_WIFI_DEVICES" = true

I encountered the same issue, using flet version 0.27.5, and here is my pyproject.toml.

dependencies = [
  "flet==0.27.5",
  "flet_audio==0.1.0",
  "flet-permission-handler==0.1.0",
  "aiohttp",
  "websockets",
  "py7zr"
]

Unable to import correctly

Image

The module does exist

Image Image

I encountered the same import error while using pyjnius by referring to the document, and the module was also properly packaged.

HG-ha avatar Mar 11 '25 08:03 HG-ha

Add this "flet_onesignal" to dependencies in pyproject.toml

arshiacomplus avatar Mar 30 '25 11:03 arshiacomplus

but i had another problem when i usedthis function:

async def main(page: ft.Page):
    page.title = "Warp Scanner"
    page.theme_mode = ft.ThemeMode.DARK
    page.padding = 20
    ph = fph.PermissionHandler()
    page.overlay.append(ph)
    def request_permission(permission, message):
        async def get_permission(permission):
            ph.request_permission(permission)  # Pass a list of permissions
            print("igo")
            # if result.get(permission) == True:  # Access the permission status correctly
            #     snake.content = ft.Text(f"{permission} Granted!", bgcolor=ft.colors.GREEN)
            # else:
            #     snake.content = ft.Text(f"{permission} Denied!", bgcolor=ft.colors.RED)
            # snake.open = True
            page.update()

        def close_dlg(accepted):
            page.close(dlg)
            if accepted:
                page.run_task(get_permission,permission)
            else:
                snake.content = ft.Text("Permission Denied!", bgcolor=ft.Colors.RED)
                snake.open = True
                page.update()
        dlg.modal = True
        dlg.title = ft.Text("Permission Request")
        dlg.content = ft.Text(message)
        dlg.actions = [
            ft.TextButton("Cancel", on_click=lambda _: close_dlg(False)),
            ft.TextButton("OK", on_click=lambda _:  close_dlg(True)),
        ]
        page.open(dlg)
        page.update()


    def test_permissions(e):
        request_permission(
            fph.PermissionType.STORAGE,
            "I need this permission to save results?"
        )
        request_permission(
            fph.PermissionType.MANAGE_EXTERNAL_STORAGE,
            "I need this permission to manage files?"
        )

btn:

    btn=ft.ElevatedButton(
                "Test Permissions",
                on_click=test_permissions,
            )

and i got this error :

2025-03-30 16:35:01,422 - ERROR - exception calling callback for <Future at 0x1fcfdd19ba0 state=finished raised TimeoutError>
Traceback (most recent call last):
  File "c:\Users\intel\AppData\Local\Programs\Python\Python313\Lib\concurrent\futures\_base.py", line 340, in _invoke_callbacks
    callback(self)
    ~~~~~~~~^^^^^^
  File "c:\Users\intel\AppData\Local\Programs\Python\Python313\Lib\site-packages\flet\core\page.py", line 892, in _on_completion
    raise exception
  File "g:\awarp\fletprojec.py", line 45, in get_permission
    ph.request_permission(permission)  # Pass a list of permissions
          ~~~~~~~~~~~~~~~^^^^^^^^^^^^~~~~~~
  File "c:\Users\intel\AppData\Local\Programs\Python\Python313\Lib\site-packages\flet_permission_handler\permission_handler.py", line 110, in request_permission
    out = self.invoke_method(
        "request_permission",
    ...<2 lines>...
        wait_timeout=wait_timeout,
    )
  File "c:\Users\intel\AppData\Local\Programs\Python\Python313\Lib\site-packages\flet\core\control.py", line 349, in invoke_method
    return self.__page._invoke_method(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^
        control_id=self.uid,
        ^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        wait_timeout=wait_timeout,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "c:\Users\intel\AppData\Local\Programs\Python\Python313\Lib\site-packages\flet\core\page.py", line 1214, in _invoke_method
    raise TimeoutError(
        f"Timeout waiting for invokeMethod {method_name}({arguments}) call"
    )
TimeoutError: Timeout waiting for invokeMethod request_permission({'of': 'manageExternalStorage'}) call

and when i used it without async it didn't do anything

arshiacomplus avatar Mar 30 '25 13:03 arshiacomplus

I think this issue is not important anymore because in flet 0.27 they added pyjnius so we have access to the native android permission interface thats works perfect. Im closing this issue. If someone wants some code about that can ask me.

SIRGPrice avatar Apr 22 '25 14:04 SIRGPrice

I think this issue is not important anymore because in flet 0.27 they added pyjnius so we have access to the native android permission interface thats works perfect. Im closing this issue. If someone wants some code about that can ask me.

Yes, please I need some help in permission handler using pyjnius

osamalzabidi avatar Apr 27 '25 17:04 osamalzabidi