flutter_sensors 0.1.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 76

flutter_sensors #

Simple sensor event listener plugin for flutter(Android & iOS).

Installation #

First add the plugin in your project. Copy the following line below dependencies in your pubspec.yaml file.

    flutter_sensors: ^0.1.5

Then you need to import the dependency.

import 'package:flutter_sensors/flutter_sensors.dart';

iOS only #

You need to add the following key-value pair into your Info.plist file inside the ios/Runner folder in your project.

<string>A reason to get the permission</string>

How to use #

You register a new listener for an specific sensor.

final stream = await SensorManager().sensorUpdates(
        sensorId: Sensors.ACCELEROMETER,
        interval: Sensors.SENSOR_DELAY_GAME,
_accelSubscription = stream.listen((sensorEvent) {
        setState(() {
          _accelData = sensorEvent.data;

Also, you can check if an specific sensor is available.

bool accelerometerAvailable =
        await SensorManager().isSensorAvailable(Sensors.ACCELEROMETER);

Remember to cancel your StreamSubscriptions after you are done with the sensor updates.


Android Only #

You can give the ID of a sensor without using the Sensors class. Example: registering a listener for the TYPE_LIGHT sensor.

int TYPE_LIGHT = 5; // TYPE_LIGHT is equals to 5
// Checking if is available.
bool isAvailable = await SensorManager().isSensorAvailable(TYPE_LIGHT);
// Initialize a stream to receive the updates.
final stream = await SensorManager().sensorUpdates(sensorId: TYPE_LIGHT);
_lightSubscription = stream.listen((sensorEvent) {
        setState(() {
          _lightData = sensorEvent.data;
 // Cancel the stream after using it.

You can get the rest of the IDs from here.

Changelog #

0.1.5 #

  • Fixed compilation error (#2). Added support for new embedding mechanism.

0.1.2 #

  • Updated Android dependencies

0.1.1 #

  • Updated description.
  • Formatted code.

0.1.0 #

  • Sensor stream to retrieve data.
  • Dynamic sensor registering in Android.
  • iOS register some specific sensors. (Check Sensors.dart class)


flutter_sensors_example #

Demonstrates how to use the flutter_sensors plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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

  flutter_sensors: ^0.1.5

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:flutter_sensors/flutter_sensors.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 Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8