flutter_compass icon indicating copy to clipboard operation
flutter_compass copied to clipboard

How to detect compass accuracy

Open abdimussa87 opened this issue 1 year ago • 2 comments

I wanted to show a calibration required gif if the compass requires calibration. How can I detect that?

abdimussa87 avatar Nov 03 '23 17:11 abdimussa87

Same here

SantiFiebke avatar Feb 29 '24 14:02 SantiFiebke

Listen compass events for accuracy. If accuracy is null, compass needs to be calibrated.

StreamSubscription<CompassEvent>? _compassSubscription;
bool _isCompassCalibrated = true;

@override
void initState() {
  super.initState();
  _compassSubscription = FlutterCompass.events?.listen((event) {
    if (!mounted) return;
    setState(() {
      _currentHeading = event.heading;
      _isCompassCalibrated = event.accuracy != null;
    });
  });
}
if (!_isCompassCalibrated)
  Padding(
    padding: const EdgeInsets.all(8.0),
    child: Text(
      'Compass is not calibrated. Please wave your device in a figure-8 motion.',
      style: TextStyle(
        color: Colors.red,
      ),
      textAlign: TextAlign.center,
    ),
  ),

xihuny avatar Jun 22 '24 09:06 xihuny