large Flutter Favorite logosmall Flutter Favorite logo

sensors_plus 2.0.1 icon indicating copy to clipboard operation
sensors_plus: ^2.0.1 copied to clipboard

Flutter plugin for accessing accelerometer, gyroscope, and magnetometer sensors.

Sensors Plus #

Flutter Community: sensors_plus

sensors_plus pub points pub package

build

A Flutter plugin to access the accelerometer, gyroscope, and magnetometer sensors.

Platform Support #

AndroidiOSMacOSWebLinuxWindows
✔️✔️✔️

Usage #

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

This will expose such classes of sensor events through a set of streams:

  • AccelerometerEvent describes 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.
  • UserAccelerometerEvent also describes 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.
  • GyroscopeEvent describes the rotation of the device.
  • MagnetometerEvent describes the ambient magnetic field surrounding the device. A compass is an example usage of this data.

These events are exposed through a BroadcastStream: accelerometerEvents, userAccelerometerEvents, gyroscopeEvents, and magnetometerEvents, respectively.

Example #

import 'package:sensors_plus/sensors_plus.dart';

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

userAccelerometerEvents.listen((UserAccelerometerEvent 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)]

magnetometerEvents.listen((MagnetometerEvent event) {
  print(event);
});
// [MagnetometerEvent (x: -23.6, y: 6.2, z: -34.9)]

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

Check out our website to learn more: Plus Plugins documentation

464
likes
130
pub points
97%
popularity

Publisher

verified publisher iconfluttercommunity.dev

Flutter plugin for accessing accelerometer, gyroscope, and magnetometer sensors.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Icon for licenses.BSD-3-Clause (LICENSE)

Dependencies

flutter, flutter_web_plugins, sensors_plus_platform_interface

More

Packages that depend on sensors_plus