Menu

1 / 5

heading_sensor: a compass heading for Flutter on Android, done carefully

DEV Community: flutter·Abdeldjalil Chougui·about 13 hours ago
#JcCO6QHm
#devtoflutter#devto#dev#heading#sensor
Reading 0:00
15s threshold

A compass screen looks simple: read a number between 0 and 360, rotate a needle. The number is the easy part. The rest is where compass apps go wrong.

The phone has several sensors that can give a heading, and they are not equally good. The heading has to follow the top of the screen, so it must change when the display rotates to landscape. A needle that is smoothed with a plain average spins the long way round when the heading goes from 359° to 1°. The sensor reports when it needs calibration, and the app should tell the user. And a magnetometer points to magnetic north, not true north.

heading_sensor is a Flutter plugin that handles those points. It reads the Android rotation-vector sensors and gives you heading, pitch and roll, a calibration accuracy, smoothing that is safe around 0°/360°, and optional true north. The README describes it as a maintained replacement for flutter_compass and flutter_compass_v2 . It is Android only.

What it does

Best sensor first. It uses TYPE_ROTATION_VECTOR .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.