Gyroscope Service
Streams gyroscope readings, reporting device rotation rate around each axis in rad/s.
**Platform Support:**
**Inheritance:**
Service.**Properties:**
cancel_on_error: bool - If True, cancels the stream subscription on the first sensor error. Defaults to True.enabled: bool - If True, the sensor is sampled. Set to False to stop streaming. Defaults to True.interval: Duration | None - Desired sampling interval. Defaults to 200ms.**Events:**
on_error: EventHandler[SensorErrorEvent] | None - Fired when the platform reports a sensor error. The event object contains an message string.on_reading: EventHandler[GyroscopeReadingEvent] | None - Fires when a new reading is available. The event object contains x, y, z (rotation rates in rad/s) and timestamp (microseconds since epoch).**Example Usage:**
import flet as ftdef main(page: ft.Page):
def handle_reading(e: ft.GyroscopeReadingEvent):
reading.value = f"x={e.x:.2f} rad/s, y={e.y:.2f} rad/s, z={e.z:.2f} rad/s"
page.update()
def handle_error(e: ft.SensorErrorEvent):
page.add(ft.Text(f"Gyroscope error: {e.message}"))
page.services.append(
ft.Gyroscope(
on_reading=handle_reading,
on_error=handle_error,
interval=ft.Duration(milliseconds=100),
)
)
page.add(
ft.Text("Rotate your device to see gyroscope readings."),
reading := ft.Text("Waiting for data..."),
)
ft.run(main)