Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit b71cb7a

Browse files
committed
remove fire-and-forget methods | remove _async in methods name
1 parent 39df482 commit b71cb7a

4 files changed

Lines changed: 56 additions & 77 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1010
### Added
1111

1212
- Deployed online documentation: https://flet-dev.github.io/flet-geolocator/
13-
- `Geolocator` control new methods: `distance_between_async`
13+
- `Geolocator` control new methods: `distance_between`
1414
- `Geolocator` control new properties: `position`, `configuration`
15-
- New dataclasses:
15+
- New dataclasses:
1616
- `GeolocatorConfiguration`
1717
- `GeolocatorWebConfiguration`
1818
- `GeolocatorIosConfiguration`
@@ -26,19 +26,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2626
#### Breaking Changes
2727

2828
- `Geolocator` must now be added to `Page.services` instead of `Page.overlay`.
29-
- `Geolocator` method `get_current_position_async` parameters changed:
29+
- `Geolocator` method `get_current_position_async` parameters changed:
3030
- removed `accuracy`
3131
- `location_settings` renamed to `configuration` (type changed)
3232
- `wait_timeout` renamed to `timeout`
3333
- In all `Geolocator` methods, parameter `wait_timeout` renamed to `timeout`.
34-
- Removed sync methods from `Geolocator`:
35-
- `get_current_position` → use `get_current_position_async` instead
36-
- `get_last_known_position` → use `get_last_known_position_async` instead
37-
- `get_permission_status` → use `get_permission_status_async` instead
38-
- `request_permission` → use `request_permission_async` instead
39-
- `is_location_service_enabled` → use `is_location_service_enabled_async` instead
40-
- `open_app_settings` → use `open_app_settings_async` instead
41-
- `open_location_settings` → use `open_location_settings_async` instead
34+
- The following `Geolocator` sync methods were made [`async`](https://docs.python.org/3/library/asyncio.html):
35+
- `get_current_position`
36+
- `get_last_known_position`
37+
- `get_permission_status`
38+
- `request_permission`
39+
- `is_location_service_enabled`
40+
- `open_app_settings`
41+
- `open_location_settings`
4242
- Enum `GeolocatorActivityType` renamed to `GeolocatorIosActivityType`
4343

4444
## [0.1.0] - 2025-01-15
@@ -47,4 +47,4 @@ Initial release.
4747

4848

4949
[0.2.0]: https://github.com/flet-dev/flet-lottie/compare/0.1.0...0.2.0
50-
[0.1.0]: https://github.com/flet-dev/flet-lottie/releases/tag/0.1.0
50+
[0.1.0]: https://github.com/flet-dev/flet-lottie/releases/tag/0.1.0

examples/geolocator_example/src/main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,36 @@ def show_snackbar(message):
3434
page.show_dialog(ft.SnackBar(ft.Text(message)))
3535

3636
async def handle_permission_request(e):
37-
p = await gl.request_permission_async(timeout=60)
37+
p = await gl.request_permission(timeout=60)
3838
page.add(ft.Text(f"request_permission: {p}"))
3939
show_snackbar(f"Permission request sent: {p}")
4040

4141
async def handle_get_permission_status(e):
42-
p = await gl.get_permission_status_async()
42+
p = await gl.get_permission_status()
4343
show_snackbar(f"Permission status: {p}")
4444

4545
async def handle_get_current_position(e):
46-
p = await gl.get_current_position_async()
46+
p = await gl.get_current_position()
4747
show_snackbar(f"Current position: ({p.latitude}, {p.longitude})")
4848

4949
async def handle_get_last_known_position(e):
50-
p = await gl.get_last_known_position_async()
50+
p = await gl.get_last_known_position()
5151
show_snackbar(f"Last known position: ({p.latitude}, {p.longitude})")
5252

5353
async def handle_location_service_enabled(e):
54-
p = await gl.is_location_service_enabled_async()
54+
p = await gl.is_location_service_enabled()
5555
show_snackbar(f"Location service enabled: {p}")
5656

5757
async def handle_open_location_settings(e):
58-
p = await gl.open_location_settings_async()
58+
p = await gl.open_location_settings()
5959
page.close(location_settings_dlg)
6060
if p is True:
6161
show_snackbar("Location settings opened successfully.")
6262
else:
6363
show_snackbar("Location settings could not be opened.")
6464

6565
async def handle_open_app_settings(e):
66-
p = await gl.open_app_settings_async()
66+
p = await gl.open_app_settings()
6767
page.close(app_settings_dlg)
6868
if p:
6969
show_snackbar("App settings opened successfully.")
@@ -91,7 +91,7 @@ async def handle_open_app_settings(e):
9191
),
9292
ft.OutlinedButton(
9393
"Get Last Known Position",
94-
visible=False if page.web else True,
94+
visible=not page.web,
9595
on_click=handle_get_last_known_position,
9696
),
9797
ft.OutlinedButton(
@@ -100,12 +100,12 @@ async def handle_open_app_settings(e):
100100
),
101101
ft.OutlinedButton(
102102
"Open Location Settings",
103-
visible=False if page.web else True, # (1)!
103+
visible=not page.web, # (1)!
104104
on_click=lambda e: page.open(location_settings_dlg),
105105
),
106106
ft.OutlinedButton(
107107
"Open App Settings",
108-
visible=False if page.web else True, # (1)!
108+
visible=not page.web, # (1)!
109109
on_click=lambda e: page.open(app_settings_dlg),
110110
),
111111
],

src/flet_geolocator/geolocator.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
from dataclasses import field
32
from typing import Optional
43

@@ -50,7 +49,7 @@ class Geolocator(ft.Service):
5049
Starts as `None` and will be updated when the position changes.
5150
"""
5251

53-
async def get_current_position_async(
52+
async def get_current_position(
5453
self,
5554
configuration: Optional[GeolocatorConfiguration] = None,
5655
timeout: float = 30,
@@ -77,16 +76,14 @@ async def get_current_position_async(
7776
Raises:
7877
TimeoutError: If the request times out.
7978
"""
80-
r = await self._invoke_method_async(
79+
r = await self._invoke_method(
8180
method_name="get_current_position",
8281
arguments={"configuration": configuration or self.configuration},
8382
timeout=timeout,
8483
)
8584
return GeolocatorPosition(**r)
8685

87-
async def get_last_known_position_async(
88-
self, timeout: float = 10
89-
) -> GeolocatorPosition:
86+
async def get_last_known_position(self, timeout: float = 10) -> GeolocatorPosition:
9087
"""
9188
Gets the last known position stored on the user's device.
9289
The accuracy can be defined using the
@@ -106,13 +103,13 @@ async def get_last_known_position_async(
106103
TimeoutError: If the request times out.
107104
"""
108105
assert not self.page.web, "get_last_known_position is not supported on web"
109-
r = await self._invoke_method_async(
106+
r = await self._invoke_method(
110107
"get_last_known_position",
111108
timeout=timeout,
112109
)
113110
return GeolocatorPosition(**r)
114111

115-
async def get_permission_status_async(
112+
async def get_permission_status(
116113
self, timeout: float = 10
117114
) -> GeolocatorPermissionStatus:
118115
"""
@@ -127,15 +124,13 @@ async def get_permission_status_async(
127124
Raises:
128125
TimeoutError: If the request times out.
129126
"""
130-
r = await self._invoke_method_async(
127+
r = await self._invoke_method(
131128
"get_permission_status",
132129
timeout=timeout,
133130
)
134131
return GeolocatorPermissionStatus(r)
135132

136-
async def request_permission_async(
137-
self, timeout: int = 60
138-
) -> GeolocatorPermissionStatus:
133+
async def request_permission(self, timeout: int = 60) -> GeolocatorPermissionStatus:
139134
"""
140135
Requests the device for access to the device's location.
141136
@@ -148,13 +143,13 @@ async def request_permission_async(
148143
Raises:
149144
TimeoutError: If the request times out.
150145
"""
151-
r = await self._invoke_method_async(
146+
r = await self._invoke_method(
152147
"request_permission",
153148
timeout=timeout,
154149
)
155150
return GeolocatorPermissionStatus(r)
156151

157-
async def is_location_service_enabled_async(self, timeout: float = 10) -> bool:
152+
async def is_location_service_enabled(self, timeout: float = 10) -> bool:
158153
"""
159154
Checks if location service is enabled.
160155
@@ -167,11 +162,9 @@ async def is_location_service_enabled_async(self, timeout: float = 10) -> bool:
167162
Raises:
168163
TimeoutError: If the request times out.
169164
"""
170-
return await self._invoke_method_async(
171-
"is_location_service_enabled", timeout=timeout
172-
)
165+
return await self._invoke_method("is_location_service_enabled", timeout=timeout)
173166

174-
async def open_app_settings_async(self, timeout: float = 10) -> bool:
167+
async def open_app_settings(self, timeout: float = 10) -> bool:
175168
"""
176169
Attempts to open the app's settings.
177170
@@ -189,31 +182,12 @@ async def open_app_settings_async(self, timeout: float = 10) -> bool:
189182
TimeoutError: If the request times out.
190183
"""
191184
assert not self.page.web, "open_app_settings is not supported on web"
192-
return await self._invoke_method_async(
185+
return await self._invoke_method(
193186
"open_app_settings",
194187
timeout=timeout,
195188
)
196189

197-
def open_location_settings(self, timeout: float = 10):
198-
"""
199-
Attempts to open the device's location settings.
200-
201-
Note:
202-
This method is not supported on web plaform.
203-
204-
Args:
205-
timeout: The maximum amount of time (in seconds) to wait for a response.
206-
207-
Returns:
208-
`True` if the device's settings were opened successfully, `False` otherwise.
209-
210-
Raises:
211-
AssertionError: If invoked on a web platform.
212-
TimeoutError: If the request times out.
213-
"""
214-
asyncio.create_task(self.open_location_settings_async(timeout=timeout))
215-
216-
async def open_location_settings_async(self, timeout: float = 10):
190+
async def open_location_settings(self, timeout: float = 10):
217191
"""
218192
Attempts to open the device's location settings.
219193
@@ -231,12 +205,12 @@ async def open_location_settings_async(self, timeout: float = 10):
231205
TimeoutError: If the request times out.
232206
"""
233207
assert not self.page.web, "open_location_settings is not supported on web"
234-
await self._invoke_method_async(
208+
await self._invoke_method(
235209
"open_location_settings",
236210
timeout=timeout,
237211
)
238212

239-
async def distance_between_async(
213+
async def distance_between(
240214
self,
241215
start_latitude: ft.Number,
242216
start_longitude: ft.Number,
@@ -263,7 +237,7 @@ async def distance_between_async(
263237
Raises:
264238
TimeoutError: If the request times out.
265239
"""
266-
await self._invoke_method_async(
240+
await self._invoke_method(
267241
method_name="distance_between",
268242
arguments={
269243
"start_latitude": start_latitude,

src/flet_geolocator/types.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,16 @@ class GeolocatorPermissionStatus(Enum):
9494
"""
9595
Permission to access the device's location is denied.
9696
97-
The app should try to request permission using the [`Geolocator.request_permission`][(p).] method.
97+
The app should try to request permission using the
98+
[`Geolocator.request_permission`][(p).] method.
9899
"""
99100

100101
DENIED_FOREVER = "deniedForever"
101102
"""
102103
Permission to access the device's location is permanently denied.
103104
104-
When requesting permissions, the permission dialog will not be shown until the user updates
105-
the permission in the app settings.
105+
When requesting permissions, the permission dialog will not be shown until the
106+
user updates the permission in the app settings.
106107
"""
107108

108109
WHILE_IN_USE = "whileInUse"
@@ -112,15 +113,16 @@ class GeolocatorPermissionStatus(Enum):
112113

113114
ALWAYS = "always"
114115
"""
115-
Permission to access the device's location is allowed even when the app is running in the background.
116+
Permission to access the device's location is allowed even when the app is
117+
running in the background.
116118
"""
117119

118120
UNABLE_TO_DETERMINE = "unableToDetermine"
119121
"""
120122
Permission status cannot be determined.
121123
122-
This status is only returned by the [`Geolocator.request_permission`][(p).] method on the web platform
123-
for browsers that did not implement the Permissions API.
124+
This status is only returned by the [`Geolocator.request_permission`][(p).] method
125+
on the web platform for browsers that did not implement the Permissions API.
124126
See: https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API
125127
"""
126128

@@ -240,7 +242,8 @@ class GeolocatorPosition:
240242
The floor specifies the floor of the building on which the device is
241243
located.
242244
243-
The floor property is only available on iOS and only when the information is available.
245+
The floor property is only available on iOS
246+
and only when the information is available.
244247
In all other cases this value will be `None`.
245248
"""
246249

@@ -363,7 +366,8 @@ class ForegroundNotificationConfiguration:
363366
"""
364367
When enabled, a WifiLock is acquired when background execution is started.
365368
This allows the application to keep the Wi-Fi radio awake, even when the
366-
user has not used the device in a while (e.g. for background network communications).
369+
user has not used the device in a while
370+
(e.g. for background network communications).
367371
368372
Wifi lock permissions should be obtained first by using a permissions library.
369373
"""
@@ -392,16 +396,17 @@ class GeolocatorAndroidConfiguration(GeolocatorConfiguration):
392396
"""
393397
Whether altitude should be calculated as MSL (EGM2008) from NMEA messages
394398
and reported as the altitude instead of using the geoidal height (WSG84). Setting
395-
this property true will help to align Android altitude to that of iOS which uses MSL.
399+
this property true will help to align Android altitude to that of iOS which
400+
uses MSL.
396401
397-
If the NMEA message is empty then the altitude reported will still be the standard WSG84
398-
altitude from the GPS receiver.
402+
If the NMEA message is empty then the altitude reported will still be
403+
the standard WSG84 altitude from the GPS receiver.
399404
400405
MSL Altitude is only available starting from Android N and not all devices support
401406
NMEA message returning $GPGGA sequences.
402407
403-
This property only works with position stream updates and has no effect when getting the
404-
current position or last known position.
408+
This property only works with position stream updates and has no effect when
409+
getting the current position or last known position.
405410
"""
406411

407412
foreground_notification_config: Optional[ForegroundNotificationConfiguration] = None

0 commit comments

Comments
 (0)