Search packages, repositories and app categories

Package detailsv1.0.1

compassx

Flutter compass plugin offering true heading, accuracy, and calibration needs.

AndroidiOS
30-day downloads
3K
Likes
20
Pub points
150

Install package

flutter pub add compassx

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

CompassX is a Flutter plugin that provides access to device compass data, including true heading, magnetic accuracy, and calibration status. It supports both Android and iOS platforms, delivering real-time orientation information through the device's sensors. The plugin is ideal for navigation, mapping, and augmented reality applications requiring precise directional input. With minimal setup via `flutter pub add compassx`, developers can integrate reliable compass functionality into their apps. The source code is publicly available on GitHub for transparency and customization.

Use cases

  • Navigation apps
  • Augmented reality experiences
  • Outdoor activity tracking
  • Map-based applications
  • Directional UI elements

Key features

  • True heading support
  • Magnetic accuracy reporting
  • Real-time sensor updates
  • Calibration status monitoring
  • Cross-platform compatibility

Suitable for

  • Developers building navigation tools
  • Apps requiring directional awareness
  • AR and location-based services
  • Mobile apps needing sensor integration

Considerations

  • Requires device with magnetometer
  • Accuracy depends on environment
  • May need user calibration
  • Background operation limited on some devices
  • iOS requires privacy permission

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

CompassX

Logo

Provides reliable compass data and extensive documentation.

Usage

StreamBuilder<CompassXEvent>(
  stream: CompassX.events,
  builder: (context, snapshot) {
    if (!snapshot.hasData) return const Text('No data');
    final compass = snapshot.data!;
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Text('Heading: ${compass.heading}'),
        Text('Accuracy: ${compass.accuracy}'),
        Text('Should calibrate: ${compass.shouldCalibrate}'),
        Transform.rotate(
          angle: compass.heading * math.pi / 180,
          child: Icon(
            Icons.arrow_upward_rounded,
            size: MediaQuery.of(context).size.width - 80,
          ),
        ),
      ],
    );
  },
),
  • heading: The heading relative to true north in degree.
  • accuracy: The accuracy of the sensor data.
  • shouldCalibrate: Whether the sensor should be calibrated or not.

Install

$ flutter pub add compassx

Check the minimum supported version of your project and update as necessary.

  • iOS: 12
  • Android: 21

Request permission to get true heading in Android. Not required on iOS.

$ flutter pub add permission_handler

Specify the permissions one or both of the following in AndroidManifest.xml. It can be copied from example.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  • ACCESS_COARSE_LOCATION: Used when normal accuracy is required.
  • ACCESS_FINE_LOCATION: Used when the highest quality accuracy is required.

Add code to request permissions.

if (Platform.isAndroid) await Permission.location.request();

CompassX heading currently supports only portrait mode. It is recommended to fix the orientation of the device.

SystemChrome.setPreferredOrientations([
        DeviceOrientation.portraitUp,
        DeviceOrientation.portraitDown,
      ]);

Testing

It is recommended to use a real device. iOS simulators cannot use the heading sensor (compass). See Testing CompassX for details.

Documentation

If you are going to use this plugin in your product apps, I strongly suggest you read full documentation carefully.

Categories

Source repository

Projects using this package

No data available yet.