-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Geolocator #3179
Geolocator #3179
Conversation
Thank you! Useful control - great PR! 👍 I'm looking at the example for Geolocator widget: https://pub.dev/packages/geolocator#example I think we need to implement methods to check/request permissions:
We obviously can't rely on an assumption the location service is allowed/enabled on user's device, right? |
In dart side waiting event(to get response from permission and service prompt) happens for infinite amount of time, but in python side I've ignorned package(geolocator) provided permission related function in current implementation, as I have better understanding about common PermissionHandler dart package. Planned to add |
…rst 4 suggestions implemented
Seems like the In any case, I suggest we go for independence: expose all the possible methods provided by the
|
yes... will expose all other functions of that package. Geolocator is directly dependent on permission_handler.dart rather than on permission_handler which is recently implemented in flet. permission_handler is intended to be used in rare scenarios only... like if user wish to check/get multiple permission on opening app. |
So, I went on and added/updated some more stuffs such as permissions, utils and the exposed methods as suggested by Feodor. I tested simultaneously on 4 platforms and it worked: android, mac, web and ios - only windows is left out now. Updated Test Codeimport flet as ft
async def main(page: ft.Page):
page.window_always_on_top = True
page.on_error = lambda e: print(f"Page Error: {e.data}")
page.scroll = ft.ScrollMode.ADAPTIVE
page.appbar = ft.AppBar(title=ft.Text("Geolocator Tests"))
gl = ft.Geolocator()
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="OK",
on_click=handler,
),
],
actions_alignment=ft.MainAxisAlignment.CENTER,
)
def handle_permission_request(e):
page.add(ft.Text(f"request_permission: {gl.request_permission()}"))
def handle_has_permission(e):
page.add(ft.Text(f"has_permission: {gl.has_permission()}"))
def handle_get_current_position(e):
p = gl.get_current_position()
page.add(ft.Text(f"get_current_position: ({p.latitude}, {p.longitude})"))
def handle_get_last_known_position(e):
p = gl.get_last_known_position()
page.add(ft.Text(f"get_last_known_position: ({p.latitude}, {p.longitude})"))
def handle_location_service_enabled(e):
page.add(
ft.Text(f"is_location_service_enabled: {gl.is_location_service_enabled()}")
)
def handle_open_location_settings(e):
page.close_dialog()
page.add(ft.Text(f"open_location_settings: {gl.open_location_settings()}"))
def handle_open_app_settings(e):
page.close_dialog()
page.add(ft.Text(f"open_app_settings: {gl.open_app_settings()}"))
page.add(
ft.Row(
[
ft.OutlinedButton(
"request_permission",
on_click=handle_permission_request,
),
ft.OutlinedButton(
"has_permission",
on_click=handle_has_permission,
),
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.show_dialog(
settings_dlg(handle_open_location_settings)
),
),
ft.OutlinedButton(
"open_app_settings",
visible=False if page.web else True,
on_click=lambda e: page.show_dialog(
settings_dlg(handle_open_app_settings)
),
),
],
wrap=True,
)
)
ft.app(main) |
3daa556
to
6e7137e
Compare
* geolocator backup * Geolocator Feature v1 * Geolocator Feature v1.1 (Junks removed) * Geolocator: Junks cleanup * Geolocator: Exception handled with clear message in geolocator.py, first 4 suggestions implemented * add Android, macOS and iOS permissions * refactor parseLocationAccuracy util * create positionToJson util * create new cases/methods and update old ones * Cleanup * Gelocator: Unused package removal --------- Co-authored-by: ndonkoHenri <[email protected]> Co-authored-by: TheEthicalBoy <[email protected]>
PR on GPS Location Feature
@FeodorFitsner @ndonkoHenri
As Stream function provided in Geolocator dart package just stops streaming when app is minimized, Initially I planned to implement location streaming using Background Service... But while trying that in a clean/pure flutter project itself I got stuck with some Kotlin version related error(which I couldn't solve). Therefore I finally decided to just have a normal function to get location in dart side and decided to call it explicitly in a loop in flet app using run_task/run_thread method to implement stream(to leave it to user's/developer's side) as implemented in the code.
playground/main.py