Geolocator service
Create or retrieve this service with page.geolocator(**properties). Ruflet reuses the registered service unless you supply a different id.
Example
location = text(value: "Location not requested")
page.add(location)
geolocator = page.geolocator
geolocator.request_permission(on_result: ->(_permission, permission_error) {
next page.update(location, value: permission_error.to_s) if permission_error
geolocator.get_current_position(on_result: ->(position, error) {
page.update(location, value: error ? error.to_s : position.inspect)
})
})
Page accessor
page.geolocator(**props)
Properties
configuration— Sets the configuration property.data— Arbitrary value you can attach to the control and read back in handlers.key— Stable identity used to preserve state across rebuilds.
Events
on_error— Fired when an error occurs.on_position_change— Fired on position change.
Service methods
distance_between(start_latitude, start_longitude, end_latitude, end_longitude, timeout: ..., on_result: ...)get_current_position(configuration: ..., timeout: ..., on_result: ...)get_last_known_position(timeout: ..., on_result: ...)get_permission_status(timeout: ..., on_result: ...)is_location_service_enabled(timeout: ..., on_result: ...)open_app_settings(timeout: ..., on_result: ...)open_location_settings(timeout: ..., on_result: ...)request_permission(timeout: ..., on_result: ...)
Result and error handling
Client calls are asynchronous. When a method accepts on_result:, handle both callback values: |result, error|. Availability and returned data can vary by platform.
Common service API
The service also supports the common Ruflet control API: attach_handler(event_name, handler), children, emit(event_name, event), has_handler?(event_name), id, merge_props(values = ...), on(event_name, &block), props, runtime_page, runtime_page=, to_patch, type, wire_id, wire_id=.
Use the named methods above for application code; common control methods mainly support event registration, updates, and runtime integration.
Wire reference
- Service helper:
geolocator - Wire type:
geolocator
Client extension setup
This service is implemented by the flet_geolocator Flet extension. Enable it in ruflet.yaml, then rebuild the client:
extensions:
- geolocator
Application code uses page.geolocator; do not add the package directly to your app's Flutter dependencies.
Declare protected access in services.yaml:
services:
- location:
description: Explain why your app needs location access.