Add the plugin as a dependency in your Flutter project's
dependencies: expo_sensors: ^0.1.0
To install it directly from our git repo, specify the dependency as shown below:
dependencies: expo_sensors: git: url: git://github.com/expo/expo.git path: packages/expo-sensors-flutter-plugin
There are five different device sensors that you can access via this plugin. These sensors are:
All three three-axis sensors provided in this plugin (
Magnetometer) contain the same set of methods and event shapes.
Each file contains an event type that has three members:
z which are all of type
The sensor class itself has an API similar to what follows:
static final Stream<GyroscopeEvent> events; static Future<dynamic> setUpdateInterval(Duration interval);
You can import a sensor modules with the line below, replacing
<sensor_name> with the actual sensor name of course.
PedometerEvent is a data class that has a single property,
steps which is of type
static final Stream<PedometerEvent> events
Pedometer.events is a stream of step counting events that lets you know how many steps one has taken since you started listening to the stream.
static Future<int> getStepCount(DateTime startDate, DateTime endDate)
Pedometer.getStepCount should be pretty self-explanatory.
startDate should be before
static Future<bool> getAvailability()
Pedometer.getAvailability will check (and ask if necessary) for permissions to access the device's pedometer.
DeviceMotionEvent have the following members:
final Map acceleration; final Map accelerationIncludingGravity; final Map rotation; final Map rotationRate; final int orientation;
The API for DeviceMotion is as follows:
static final Stream<DeviceMotionEvent> events
DeviceMotion.events is pretty self-explanatory.
static Future<dynamic> setUpdateInterval(Duration interval)
DeviceMotion.setUpdateInterval is pretty self-explanatory too.
static Future<double> getGravity()
DeviceMotion.getGravity returns the measured gravity variable from your device.
Add this to your package's pubspec.yaml file:
dependencies: expo_sensors: ^0.1.0
You can install packages from the command line:
$ flutter pub get
Alternatively, your editor might support
flutter pub get.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:expo_sensors/accelerometer.dart'; import 'package:expo_sensors/device_motion.dart'; import 'package:expo_sensors/gyroscope.dart'; import 'package:expo_sensors/magnetometer.dart'; import 'package:expo_sensors/pedometer.dart';
|0.1.0||Feb 17, 2019|
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
We analyzed this package on Jun 25, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Support latest dependencies. (-5 points)
The version constraint in
pubspec.yaml does not support the latest published versions for 1 dependency.
Maintain an example. (-10 points)
Create a short demo in the
example/ directory to show how to use this package.
Common filename patterns include
expo_sensors.dart. Packages with multiple examples should provide
For more information see the pub package layout conventions.
The package description is too short. (-5 points)
Add more detail to the
description field of
pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.