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.