tree: d4d3eef1b6f7da4f95225c5b56c569f1d7f5d85a [path history] [tgz]
  1. android/
  2. example/
  3. ios/
  4. lib/
  5. test/
  6. CHANGELOG.md
  7. LICENSE
  8. pubspec.yaml
  9. README.md
packages/sensors/README.md

sensors

A Flutter plugin to access the accelerometer and gyroscope sensors.

Usage

To use this plugin, add sensors as a dependency in your pubspec.yaml file.

This will expose three classes of sensor events, through three different streams.

  • AccelerometerEvents describe the velocity of the device, including the effects of gravity. Put simply, you can use accelerometer readings to tell if the device is moving in a particular direction.
  • UserAccelerometerEvents also describe the velocity of the device, but don‘t include gravity. They can also be thought of as just the user’s affect on the device.
  • GyroscopeEvents describe the rotation of the device.

Each of these is exposed through a BroadcastStream: accelerometerEvents, userAccelerometerEvents, and gyroscopeEvents, respectively.

Example

import 'package:sensors/sensors.dart';

accelerometerEvents.listen((AccelerometerEvent event) {
  print(event);
});
// [AccelerometerEvent (x: 0.0, y: 9.8, z: 0.0)]

userAccelerometerEvents.listen((AccelerometerEvent event) {
  print(event);
});
// [UserAccelerometerEvent (x: 0.0, y: 0.0, z: 0.0)]

gyroscopeEvents.listen((GyroscopeEvent event) {
  print(event);
});
// [GyroscopeEvent (x: 0.0, y: 0.0, z: 0.0)]

Also see the example subdirectory for an example application that uses the sensor data.