expo_sensors 0.1.0

  • Readme
  • Changelog
  • Installing
  • 81

expo_sensors #

A Flutter plugin for the expo-sensors Universal Module. It requires expo-sensors to be installed and linked as well as expo-flutter-adapter to installed as a peer dependency in your Flutter project.

Getting Started #

Installation #

Add the plugin as a dependency in your Flutter project's pubspec.yaml file.

  expo_sensors: ^0.1.0

To install it directly from our git repo, specify the dependency as shown below:

      url: git://github.com/expo/expo.git
      path: packages/expo-sensors-flutter-plugin

Usage #

There are five different device sensors that you can access via this plugin. These sensors are: Accelerometer, Gyroscope, Magnetometer, Pedometer, and DeviceMotion.

Three-Axis Sensors #

All three three-axis sensors provided in this plugin (Accelerometer, Gyroscope, and Magnetometer) contain the same set of methods and event shapes.

Each file contains an event type that has three members: x, y, and z which are all of type double.

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.

import 'package:expo_sensors/<sensor_name>.dart';

Pedometer #

PedometerEvent #

PedometerEvent is a data class that has a single property, steps which is of type int.

Pedometer #

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 endDate.

static Future<bool> getAvailability()

Pedometer.getAvailability will check (and ask if necessary) for permissions to access the device's pedometer.

DeviceMotion #

DeviceMotionEvent #

Instances of DeviceMotionEvent have the following members:

  final Map acceleration;
  final Map accelerationIncludingGravity;
  final Map rotation;
  final Map rotationRate;
  final int orientation;

DeviceMotion #

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.

0.1.0 #

  • This initial release allows Flutter developers to access the device's sensor streams and call upon certain methods related to those modules.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  expo_sensors: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

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';
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]
Learn more about scoring.

We analyzed this package on Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and expo_sensors.dart. Packages with multiple examples should provide example/README.md.

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.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
expo_flutter_adapter ^0.1.0 0.1.1
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8