Magnetometer

Streams magnetometer readings reporting the ambient magnetic field (uT) per axis. Suitable for compass-style applications.

**Platform Support:**

  • Android
  • iOS
  • **Limitations:**

  • APIs are not available on Web or Desktop. Always handle on_error to detect unsupported hardware.
  • **Inheritance:**

  • Inherits from flet.Service.
  • Properties

  • **cancel_on_error**: bool
  • * Description: Whether the stream subscription should cancel on the first sensor error. * Default: True
  • **enabled**: bool
  • * Description: Whether the sensor should be sampled. Disable to stop streaming. * Default: True
  • **interval**: Duration | None
  • * Description: Desired sampling interval. * Default: Duration(milliseconds=200)

    Events

  • **on_error**: EventHandler[SensorErrorEvent] | None
  • * Description: Fired when the platform reports a sensor error. event.message contains the error description.
  • **on_reading**: EventHandler[MagnetometerReadingEvent] | None
  • * Description: Fires when a new reading is available. * Event Data: event contains x, y, z magnetic field strengths (uT) and timestamp (microseconds since epoch).