compassx

Creator: coderz1093

Last updated:

0 purchases

compassx Image
compassx Images

Languages

Categories

Add to Cart

Description:

compassx

CompassX #

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,
),
),
],
);
},
),
copied to clipboard

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
copied to clipboard
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
copied to clipboard
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" />
copied to clipboard

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();
copied to clipboard
CompassX heading currently supports only portrait mode. It is recommended to fix the orientation of the device.
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
copied to clipboard
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.

True Heading vs Magnetic Heading
How to calibrate your device's compass

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.