Flashlight service
Create or retrieve this service with page.flashlight(**properties). Ruflet reuses the registered service unless you supply a different id.
Example
status = text(value: "Checking flashlight…")
page.add(status)
flashlight = page.flashlight
flashlight.is_available(on_result: ->(available, error) {
if error || !available
page.update(status, value: error ? error.to_s : "Flashlight unavailable")
else
flashlight.on(on_result: ->(_result, on_error) {
page.update(status, value: on_error ? on_error.to_s : "Flashlight on")
})
end
})
Page accessor
page.flashlight(**props)
Properties
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.
Page proxy methods
Calling page.flashlight with no properties returns a focused proxy with these methods:
is_available(timeout: ..., on_result: ...)off(timeout: ..., on_result: ...)on(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:
flashlight - Wire type:
flashlight
Client extension setup
This service is implemented by the flet_flashlight Flet extension. Enable it in ruflet.yaml, then rebuild the client:
extensions:
- flashlight
Application code uses page.flashlight; do not add the package directly to your app's Flutter dependencies.
Declare protected access in services.yaml:
services:
- camera:
description: Explain why your app needs camera access.