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.29k stars 397 forks source link

Permission Request window don't open #3561

Closed burhansvural closed 2 weeks ago

burhansvural commented 2 weeks ago

Question

Permission Request window don't open. Android CAT Error : No permissions found in manifest

Code sample

import flet as ft

def main(page: ft.Page):
    page.scroll = ft.ScrollMode.ADAPTIVE
    page.appbar = ft.AppBar(title=ft.Text("PermissionHandler Tests"))
    ph = ft.PermissionHandler()
    page.overlay.append(ph)

    def check_permission(e):
        o1 = ph.check_permission(e.control.data[0])
        page.add(ft.Text(f"Checked {e.control.data[0].name}: {o1}"))

    def request_permission(e):
        o1 = ph.request_permission(e.control.data[0])
        page.add(ft.Text(f"Requested {e.control.data[0].name}: {o1}"))

    def open_app_settings(e):
        o = ph.open_app_settings()
        page.add(ft.Text(f"App Settings: {o}"))

    page.add(
        ft.OutlinedButton(
            "Check Contacts Permission",
            data=[ft.PermissionType.PHONE,ft.PermissionType.CONTACTS],
            on_click=check_permission,
        ),
        ft.OutlinedButton(
            "Request Contacts Permission",
            data=[ft.PermissionType.PHONE,ft.PermissionType.CONTACTS],
            on_click=request_permission,
        ),
        ft.OutlinedButton(
            "Open App Settings",
            on_click=open_app_settings,
        ),
    )

ft.app(target=main,assets_dir="assets")

Error message

2024-06-25 18:10:29.600  1037-1037  StatusBarIconController com.android.systemui                 D  ignoring old pipeline callback because the new wifi icon is enabled
2024-06-25 18:10:32.607  1037-1037  StatusBarIconController com.android.systemui                 D  ignoring old pipeline callback because the new wifi icon is enabled
2024-06-25 18:10:33.059  1309-1309  TaplEvents              com...le.android.apps.nexuslauncher  D  TIS / TouchInteractionService.onInputEvent: MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=373.98535, y[0]=489.96094, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=17535755, downTime=17535755, deviceId=4, source=0x5002, displayId=0, eventId=98363782 }
2024-06-25 18:10:33.093 25136-25161 EGL_emulation           com.flet.per_handler                 D  app_time_stats: avg=1248.05ms min=0.43ms max=14965.32ms count=12
2024-06-25 18:10:33.166  1309-1309  TaplEvents              com...le.android.apps.nexuslauncher  D  TIS / TouchInteractionService.onInputEvent: MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0]=373.98535, y[0]=489.96094, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=17535863, downTime=17535755, deviceId=4, source=0x5002, displayId=0, eventId=70898747 }
2024-06-25 18:10:33.176   418-3188  audioserver             audioserver                          D  FGS Logger Transaction failed
2024-06-25 18:10:33.176   418-3188  audioserver             audioserver                          D  -129
2024-06-25 18:10:33.181 25136-25136 permissions_handler     com.flet.per_handler                 D  No permissions found in manifest for: []8
2024-06-25 18:10:33.191   589-2597  Compatibil...geReporter system_server                        D  Compat change id reported: 197654537; UID 10206; state: ENABLED
2024-06-25 18:10:33.226   418-509   AudioFlinger            audioserver                          D  mixer(0x7425dce46930) throttle end: throttle time(33)
2024-06-25 18:10:33.340   418-509   audioserver             audioserver                          D  FGS Logger Transaction failed
2024-06-25 18:10:33.340   418-509   audioserver             audioserver                          D  -129
2024-06-25 18:10:36.219   386-6361  android.ha...mpl.ranchu android.hardware.audio.service       D  threadLoop: entering standby, frames: 16011008
2024-06-25 18:10:37.118  1037-1037  StatusBarIconController com.android.systemui                 D  ignoring old pipeline callbacks, because the new mobile icons are enabled
2024-06-25 18:10:47.119  1037-1037  StatusBarIconController com.android.systemui                 D  ignoring old pipeline callbacks, because the new mobile icons are enabled
2024-06-25 18:10:50.138   589-1380  ProcessStats            system_server                        W  Tracking association SourceState{7e9f983 com.google.android.gms.persistent/10126 BFgs #29094} whose proc state 4 is better than process ProcessState{faed33b com.google.android.gms/10126 pkg=com.google.android.gms} proc state 8 (20 skipped)


### ------------------------------------------------------

- [X] I have searched for answers to my question both in the issues and in previous discussions.

_Originally posted by @burhansvural in https://github.com/flet-dev/flet/discussions/3538_
ndonkoHenri commented 2 weeks ago

What type of android device do you test on? Please provide some more details for testing.

burhansvural commented 2 weeks ago

Pixel 3a API 34 x86_64 Emulator Pixel 8 Pro API 35 x86_64 Emulator Redmi Note8 - Android 11 RKQ1 - MIUI 12.5.2 Poco - Android 12 SKQ1 - MIUI Global 13.0.1 Samsung Galaxy A31 - Android 12 - One UI 4.1 Redmi Note 10S - Android 12 SP1A - MIUI 13.0.13

NHLOCAL commented 2 weeks ago

I also encountered a similar problem with requesting permissions on Android 12

NHLOCAL commented 2 weeks ago

I tried the basic example on the page https://flet.dev/docs/controls/permissionhandler/ for an initial test of the usage But in practice, clicking did not open a permission request. It didn't show up as an option in the settings either. In practice, permissions that were already open remained so, and blocked permissions remained blocked

ndonkoHenri commented 2 weeks ago

Ah, @burhansvural, seems like you are trying to check/request the contacts permissions. It doesnt work certainly because the flet-build-template doesnt contain these permissions yet.

Why? What we were trying to avoid is to have all these permissions (contacts, camera, phone, calendar etc) in the build-template because not everyone will need, and it might also lead to rejection of apps when they are submitted to the stores: "why does your app needs all these permissions, though it seems like it doesn't makes use of all?"

In #3345 (subscribe to it), we could make everything dynamic: on could define from that file which permissions should be added to the build-template, so that only the required/used permissions are included.


However, you can download the flet-build-template and add these permissions to it yourself. Simply add the highlighted lines below, to the corresponding files in the template:

@NHLOCAL, can you please be more precise? What permissions did you try to request? The above explanation might also apply to you.

NHLOCAL commented 2 weeks ago

I would like to add write permissions on folders, including:

NHLOCAL commented 2 weeks ago

I followed the instructions, but got the following error:

command:

flet build apk core --template C:\Users\user\Documents\GitHub\flet-build-template --template-ref 0.23.1 --org nhlocal --company "NH Local" --copyright "© 2024 NH Local" --build-version 13.2.0 --build-number 13200 --splash-color #0E2B59 --splash-dark-color #FFC300 --project singlessorter

output:

[08:53:26] Created Flutter bootstrap project from
           C:\Users\משתמש\Documents\GitHub\flet-build-template with ref
           0.23.1 ✅
           Customized app icons and splash images ✅
[08:53:46] Generated app icons ✅
[08:53:53] Generated splash screens ✅
[08:56:45] Packaged Python app ✅
[09:01:31] Resolving dependencies...
             collection 1.18.0 (1.19.0 available)
             file_picker 8.0.5 (8.0.6 available)
             fl_chart 0.65.0 (0.68.0 available)
             flutter_lints 2.0.3 (4.0.0 available)
             flutter_markdown 0.6.23 (0.7.3 available)
             flutter_plugin_android_lifecycle 2.0.19 (2.0.20 available)
             http_parser 4.0.2 (4.1.0 available)
             intl 0.18.1 (0.19.0 available)
             js 0.6.7 (0.7.1 available)
             lints 2.1.1 (4.0.0 available)
             material_color_utilities 0.8.0 (0.12.0 available)
             meta 1.11.0 (1.15.0 available)
           ! package_info_plus 8.0.0 (overridden)
             path_provider_android 2.2.4 (2.2.6 available)
             sensors_plus 4.0.2 (5.0.1 available)
             shared_preferences_android 2.2.2 (2.2.3 available)
             url_launcher_android 6.3.2 (6.3.3 available)
           ! wakelock_plus 1.2.5 (overridden)
             web_socket_channel 2.4.5 (3.0.0 available)
             win32 5.5.0 (5.5.1 available)
           Got dependencies!
           18 packages have newer versions incompatible with dependency
           constraints.
           Try `flutter pub outdated` for more information.

           Running Gradle task 'assembleRelease'...
           Checking the license for package Android SDK Build-Tools 34 in
           C:\Users\me\AppData\Local\Android\Sdk\licenses
           License for package Android SDK Build-Tools 34 accepted.
           Preparing "Install Android SDK Build-Tools 34 v.34.0.0".
           "Install Android SDK Build-Tools 34 v.34.0.0" ready.
           Installing Android SDK Build-Tools 34 in
           C:\Users\me\AppData\Local\Android\Sdk\build-tools\34.0.0
           "Install Android SDK Build-Tools 34 v.34.0.0" complete.
           "Install Android SDK Build-Tools 34 v.34.0.0" finished.
           Running Gradle task 'assembleRelease'...
           283.2s

           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/borders.
           dart:122:1: Error: Type 'WidgetStateBorderSide' not found.
           WidgetStateBorderSide? parseWidgetStateBorderSide(
           ^^^^^^^^^^^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/borders.
           dart:138:45: Error: Type 'WidgetStateBorderSide' not found.
           class WidgetStateBorderSideFromJSON extends WidgetStateBorderSide
           {
                                                       ^^^^^^^^^^^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/borders.
           dart:158:27: Error: Type 'WidgetState' not found.
             BorderSide? resolve(Set<WidgetState> states) {
                                     ^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/colors.d
           art:242:1: Error: Type 'WidgetStateProperty' not found.
           WidgetStateProperty<Color?>? parseWidgetStateColor(
           ^^^^^^^^^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/icons.da
           rt:17:1: Error: Type 'WidgetStateProperty' not found.
           WidgetStateProperty<Icon?>? parseWidgetStateIcon(
           ^^^^^^^^^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/material
           _state.dart:3:1: Error: Type 'WidgetStateProperty' not found.
           WidgetStateProperty<T?>? getWidgetStateProperty<T>(
           ^^^^^^^^^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/material
           _state.dart:16:38: Error: Type 'WidgetStateProperty' not found.
           class WidgetStateFromJSON<T> extends WidgetStateProperty<T?> {
                                                ^^^^^^^^^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/material
           _state.dart:34:18: Error: Type 'WidgetState' not found.
             T? resolve(Set<WidgetState> states) {
                            ^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/borders.
           dart:158:27: Error: 'WidgetState' isn't a type.
             BorderSide? resolve(Set<WidgetState> states) {
                                     ^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/colors.d
           art:57:21: Error: The getter 'surfaceContainerHighest' isn't
           defined for the class 'ColorScheme'.
            - 'ColorScheme' is from
           'package:flutter/src/material/color_scheme.dart'
           ('../../../../first-flet-app/flutter/packages/flutter/lib/src/mat
           erial/color_scheme.dart').
           Try correcting the name to the name of an existing getter, or
           defining a getter or field named 'surfaceContainerHighest'.
                 return scheme.surfaceContainerHighest;
                               ^^^^^^^^^^^^^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/material
           _state.dart:34:18: Error: 'WidgetState' isn't a type.
             T? resolve(Set<WidgetState> states) {
                            ^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/utils/theme.da
           rt:205:5: Error: No named parameter with the name
           'surfaceContainerHighest'.
               surfaceContainerHighest: parseColor(null,
           j["surface_variant"]),
               ^^^^^^^^^^^^^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/controls/check
           box.dart:117:7: Error: 'WidgetStateBorderSide' isn't a type.
                 WidgetStateBorderSide? side = parseWidgetStateBorderSide(
                 ^^^^^^^^^^^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/controls/cuper
           tino_button.dart:126:33: Error: The getter 'WidgetState' isn't
           defined for the class '_CupertinoButtonControlState'.
            - '_CupertinoButtonControlState' is from
           'package:flet/src/controls/cupertino_button.dart'
           ('../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/controls/cup
           ertino_button.dart').
           Try correcting the name to the name of an existing getter, or
           defining a getter or field named 'WidgetState'.
                     ?.resolve(selected ? {WidgetState.selected} : {});
                                           ^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/controls/cuper
           tino_button.dart:131:33: Error: The getter 'WidgetState' isn't
           defined for the class '_CupertinoButtonControlState'.
            - '_CupertinoButtonControlState' is from
           'package:flet/src/controls/cupertino_button.dart'
           ('../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/controls/cup
           ertino_button.dart').
           Try correcting the name to the name of an existing getter, or
           defining a getter or field named 'WidgetState'.
                     ?.resolve(selected ? {WidgetState.selected} : {});
                                           ^^^^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/controls/list_
           tile.dart:131:9: Error: No named parameter with the name
           'minTileHeight'.
                   minTileHeight: control.attrDouble("minHeight"),
                   ^^^^^^^^^^^^^
           ../../../../first-flet-app/flutter/packages/flutter/lib/src/mater
           ial/list_tile.dart:332:9: Context: Found this candidate, but the
           arguments don't match.
             const ListTile({
                   ^^^^^^^^
           ../../Pub/Cache/hosted/pub.dev/flet-0.23.2/lib/src/controls/highl
           ight_view.dart:97:43: Error: The getter 'surfaceContainerHighest'
           isn't defined for the class 'ColorScheme'.
            - 'ColorScheme' is from
           'package:flutter/src/material/color_scheme.dart'
           ('../../../../first-flet-app/flutter/packages/flutter/lib/src/mat
           erial/color_scheme.dart').
           Try correcting the name to the name of an existing getter, or
           defining a getter or field named 'surfaceContainerHighest'.
                       Theme.of(context).colorScheme.surfaceContainerHighest
           );
                                                     ^^^^^^^^^^^^^^^^^^^^^^^
           Target kernel_snapshot failed: Exception

           FAILURE: Build failed with an exception.

           * What went wrong:
           Execution failed for task ':app:compileFlutterBuildRelease'.
           > Process 'command
           'C:\Users\me\first-flet-app\flutter\bin\flutter.bat'' finished
           with non-zero exit value 1

           * Try:
           > Run with --stacktrace option to get the stack trace.
           > Run with --info or --debug option to get more log output.
           > Run with --scan to get full insights.
           > Get more help at https://help.gradle.org.

           BUILD FAILED in 4m 41s
           Gradle task assembleRelease failed with exit code 1

[09:01:32] Error building Flet app - see the log of failed command above.
ndonkoHenri commented 2 weeks ago

Upgrade your flutter version to at least 3.22.2

burhansvural commented 2 weeks ago

Ah, @burhansvural, seems like you are trying to check/request the contacts permissions. It doesnt work certainly because the flet-build-template doesnt contain these permissions yet.

Why? What we were trying to avoid is to have all these permissions (contacts, camera, phone, calendar etc) in the build-template because not everyone will need, and it might also lead to rejection of apps when they are submitted to the stores: "why does your app needs all these permissions, though it seems like it doesn't makes use of all?"

In #3345 (subscribe to it), we could make everything dynamic: on could define from that file which permissions should be added to the build-template, so that only the required/used permissions are included.

However, you can download the flet-build-template and add these permissions to it yourself. Simply add the highlighted lines below, to the corresponding files in the template:

Then follow this when running flet build.

@NHLOCAL, can you please be more precise? What permissions did you try to request? The above explanation might also apply to you.

@ndonkoHenri Because I am now trying to make a WhatsApp-like application, which I had previously prepared with the Java programming language, with Python Flet, and these permissions are required. Also, your answer was very descriptive. Thank you.

Can you make a small video on how I can do this?