Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to detect compass accuracy #97

Open
abdimussa87 opened this issue Nov 3, 2023 · 2 comments
Open

How to detect compass accuracy #97

abdimussa87 opened this issue Nov 3, 2023 · 2 comments

Comments

@abdimussa87
Copy link

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

@SantiFiebke
Copy link

Same here

@xihuny
Copy link

xihuny commented Jun 22, 2024

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,
    ),
  ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants