flet icon indicating copy to clipboard operation
flet copied to clipboard

Geolocator permission

Open Gorkor227 opened this issue 1 year ago • 9 comments

Duplicate Check

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

Describe the bug

I can't get geolocator permissions on android 14.

dependencies = [ "flet==0.27.6", "flet-geolocator", ]

Code sample

Code
import flet as ft


async def main(page: ft.Page):
    page.scroll = ft.ScrollMode.ADAPTIVE
    page.appbar = ft.AppBar(title=ft.Text("Geolocator Tests"))

    def handle_position_change(e):
        page.add(ft.Text(f"New position: {e.latitude} {e.longitude}"))

    gl = ft.Geolocator(
        location_settings=ft.GeolocatorSettings(
            accuracy=ft.GeolocatorPositionAccuracy.LOW
        ),
        on_position_change=handle_position_change,
        on_error=lambda e: page.add(ft.Text(f"Error: {e.data}")),
    )
    page.overlay.append(gl)

    settings_dlg = lambda handler: ft.AlertDialog(
        adaptive=True,
        title=ft.Text("Opening Location Settings..."),
        content=ft.Text(
            "You are about to be redirected to the location/app settings. "
            "Please locate this app and grant it location permissions."
        ),
        actions=[ft.TextButton(text="Take me there", on_click=handler)],
        actions_alignment=ft.MainAxisAlignment.CENTER,
    )

    async def handle_permission_request(e):
        p = await gl.request_permission_async(wait_timeout=60)
        page.add(ft.Text(f"request_permission: {p}"))

    async def handle_get_permission_status(e):
        p = await gl.get_permission_status_async()
        page.add(ft.Text(f"get_permission_status: {p}"))

    async def handle_get_current_position(e):
        p = await gl.get_current_position_async()
        page.add(ft.Text(f"get_current_position: ({p.latitude}, {p.longitude})"))

    async def handle_get_last_known_position(e):
        p = await gl.get_last_known_position_async()
        page.add(ft.Text(f"get_last_known_position: ({p.latitude}, {p.longitude})"))

    async def handle_location_service_enabled(e):
        p = await gl.is_location_service_enabled_async()
        page.add(ft.Text(f"is_location_service_enabled: {p}"))

    async def handle_open_location_settings(e):
        p = await gl.open_location_settings_async()
        page.close(location_settings_dlg)
        page.add(ft.Text(f"open_location_settings: {p}"))

    async def handle_open_app_settings(e):
        p = await gl.open_app_settings_async()
        page.close(app_settings_dlg)
        page.add(ft.Text(f"open_app_settings: {p}"))

    location_settings_dlg = settings_dlg(handle_open_location_settings)
    app_settings_dlg = settings_dlg(handle_open_app_settings)

    page.add(
        ft.Row(
            wrap=True,
            controls=[
                ft.OutlinedButton(
                    "Request Permission",
                    on_click=handle_permission_request,
                ),
                ft.OutlinedButton(
                    "Get Permission Status",
                    on_click=handle_get_permission_status,
                ),
                ft.OutlinedButton(
                    "Get Current Position",
                    on_click=handle_get_current_position,
                ),
                ft.OutlinedButton(
                    "Get Last Known Position",
                    visible=False if page.web else True,
                    on_click=handle_get_last_known_position,
                ),
                ft.OutlinedButton(
                    "Is Location Service Enabled",
                    on_click=handle_location_service_enabled,
                ),
                ft.OutlinedButton(
                    "Open Location Settings",
                    visible=False if page.web else True,
                    on_click=lambda e: page.open(location_settings_dlg),
                ),
                ft.OutlinedButton(
                    "Open App Settings",
                    visible=False if page.web else True,
                    on_click=lambda e: page.open(app_settings_dlg),
                ),
            ],
        )
    )


ft.app(main)

To reproduce

No location permissions are defined in the manifest,

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

Windows

Operating system details

windows 10

Flet version

0.27.6

Regression

Yes, it used to work in a previous Flet version (please specify the version in additional details)

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Gorkor227 avatar Mar 16 '25 18:03 Gorkor227

Use Geolocator classes from flet_geolocator module, like in the example here: https://github.com/flet-dev/flet-geolocator?tab=readme-ov-file#example

FeodorFitsner avatar Mar 16 '25 19:03 FeodorFitsner

Use Geolocator classes from flet_geolocator module, like in the example here: https://github.com/flet-dev/flet-geolocator?tab=readme-ov-file#example

Screenshot_20250317_090257.jpg

pyproject.toml dependencies flet-geolocator==0.1.0

Gorkor227 avatar Mar 17 '25 02:03 Gorkor227

Uninstall the app from the app before deploying an updated version.

FeodorFitsner avatar Mar 17 '25 02:03 FeodorFitsner

Screenshot_20250317_091257.jpg

Uninstall the app from the app before deploying an updated version.

Gorkor227 avatar Mar 17 '25 02:03 Gorkor227

This is how to define permissions: https://flet.dev/docs/publish/android#permissions, https://flet.dev/docs/publish#cross-platform-permissions

[tool.flet.android.permission]
"android.permission.ACCESS_FINE_LOCATION" = true
"android.permission.ACCESS_COARSE_LOCATION" = true

FeodorFitsner avatar Mar 17 '25 02:03 FeodorFitsner

I have to add the --android-permissions parameter to package it for it to work. If only the following method is used, it doesn't work. I don't know if it is a bug [tool.flet.android.permission] "android.permission.ACCESS_FINE_LOCATION" = true "android.permission.ACCESS_COARSE_LOCATION" = true

Gorkor227 avatar Mar 18 '25 08:03 Gorkor227

it should be [tool.flet.android.permissions] (s at the end)

ndonkoHenri avatar Mar 18 '25 12:03 ndonkoHenri

I gave it a try and it works on my end:

Image

Can you navigate to /build/flutter/android/app/src/main/AndroidManifest.xml and share the content here?

ndonkoHenri avatar Mar 18 '25 17:03 ndonkoHenri

Use Geolocator classes from flet_geolocator module, like in the example here: https://github.com/flet-dev/flet-geolocator?tab=readme-ov-file#example

Screenshot_20250317_090257.jpg

pyproject.toml dependencies flet-geolocator==0.1.0

@FeodorFitsner also facing issue with flet-permission-handler and flet-one signal even added in dependencies

Screenshot_20250325-175910.jpg