https://github.com/madbrains/gravity-sensor-flutter
Flutter plugin to access the gravity sensor of the device.
https://github.com/madbrains/gravity-sensor-flutter
Last synced: 10 months ago
JSON representation
Flutter plugin to access the gravity sensor of the device.
- Host: GitHub
- URL: https://github.com/madbrains/gravity-sensor-flutter
- Owner: MadBrains
- License: mit
- Created: 2024-10-24T13:05:12.000Z (about 1 year ago)
- Default Branch: dev
- Last Pushed: 2024-10-30T13:36:11.000Z (about 1 year ago)
- Last Synced: 2025-01-16T06:27:45.522Z (12 months ago)
- Language: Dart
- Size: 103 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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`](https://developer.apple.com/documentation/bundleresources/information_property_list/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:
```xml
NSMotionUsageDescription
This app requires access to the device motion data to provide gravity information.
```
> [!CAUTION]
>
> Adding [`NSMotionUsageDescription`](https://developer.apple.com/documentation/bundleresources/information_property_list/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
```dart
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][example] is in the corresponding folder
[example]: https://github.com/MadBrains/Gravity-Sensor-Flutter/tree/main/example