gravity_sensor 1.0.1 copy "gravity_sensor: ^1.0.1" to clipboard
gravity_sensor: ^1.0.1 copied to clipboard

Flutter plugin to access the gravity sensor of the device.

gravity_sensor #

Flutter plugin to access the gravity sensor of the device.

Usage #

Add gravity_sensor as a dependency in your pubspec.yaml file.

On iOS you must also include a key called NSMotionUsageDescription in your app's Info.plist file. This key provides a message that tells the user why the app is requesting access to the device’s motion data.

Example Info.plist entry:

<key>NSMotionUsageDescription</key>
<string>This app requires access to the device motion data to provide gravity information.</string>

Caution

Adding NSMotionUsageDescription is a requirement and not doing so will crash your app when it attempts to access motion data.

Note

Some low end or old Android devices don't have gravity sensor available. Plugin won't crash the app, but it is highly recommended to add onError() to handle such cases gracefully.

Example #

import 'package:gravity_sensor/gravity_sensor.dart';

GravitySensor().gravityEvents.listen(
      (GravityEvent event) => print(event),
      onError: (error) {
        // Logic to handle error
        // Needed for Android in case sensor is not available
      },
      cancelOnError: true,
    );

The full Example is in the corresponding folder

1
likes
140
points
16
downloads

Publisher

verified publishermadbrains.ru

Weekly Downloads

Flutter plugin to access the gravity sensor of the device.

Homepage
Repository (GitHub)
View/report issues

Topics

#flutter #native #gravity #sensor #utils

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on gravity_sensor