rawsensors 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 56

rawsensors

A flutter plugin that lets you access raw data from sensors The goal of this plugin is to expose every sensors from the Android and IOS framework.

Features #

The different sensor types available are exposed via the enum SensorType: | SensorType | Android | IOS | |---------------|--------------------------|-----------------| | accelerometer | TYPE_ACCELEROMETER | Not implemented | | temperature | TYPE_AMBIENT_TEMPERATURE | Not implemented | | gyroscope | TYPE_GYROSCOPE | Not implemented | | magnetometer | TYPE_MAGNETIC_FIELD | Not implemented | | light | TYPE_LIGHT | Not implemented | | pressure | TYPE_PRESSURE | Not implemented |

Warning: This plugin does not support IOS for now, I would greatly appreciate some help to support IOS.

Usage #

To use this plugin, add rawsensors as a dependency in your pubspec.yaml file. For example:

dependencies:
  rawsensors: 0.0.3

Example #

import 'package:rawsensors/rawsensors.dart';

RawSensors.getSensorStream(SensorType.accelerometer)
  .then((Stream sensorStream) => {
    if (sensorStream != null) {
      sensorStream.listen((dynamic data) {
        print(data);
      }
    } else {
      print("No accelerometer found on device");
    }
  }));

Issues #

If you have any issue, bug or feature request please open an issue.

Contribution #

Contributions are welcomed, feel free to contribute if you see any improvement or you want to add new features.

License #

MIT TrAyZeN

0.0.3 #

Add pressure sensor, add isSensorAvailable method Improve documentation, improve example

0.0.2 #

Format code, improve documentation and examples.

0.0.1 #

Initial release with Android support for accelerometer, tempareture sensor, gyroscope, magnetometer and light sensor.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:rawsensors/rawsensors.dart';

import 'dart:async';

void main() => runApp(MaterialApp(
      title: 'rawsensors example',
      home: HomeScreen(),
    ));

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('rawsensors example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: SensorType.values
                .map((t) => RaisedButton(
                      child: Text(t.toString().split('.').last),
                      onPressed: () {
                        Navigator.push(
                            context,
                            MaterialPageRoute(
                                builder: (context) => SensorScreen(t)));
                      },
                    ))
                .toList(),
          ),
        ),
      ),
    );
  }
}

class SensorScreen extends StatefulWidget {
  final SensorType sensorType;

  SensorScreen(this.sensorType);

  @override
  _SensorScreenState createState() => _SensorScreenState();
}

class _SensorScreenState extends State<SensorScreen>
    with WidgetsBindingObserver {
  StreamSubscription<List<double>> _streamSubscription;
  List<double> _data;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.sensorType.toString().split('.').last),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: _data
                  ?.asMap()
                  ?.entries
                  ?.map((entry) => Text(
                      'data[${entry.key}] = ${entry.value.toStringAsFixed(10)}'))
                  ?.toList() ??
              <Widget>[Text('Unknown')],
        ),
      ),
    );
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      _subscribeToSensorDataStream();
    } else {
      _unsubscribeFromSensorDataStream();
    }
  }

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);

    _subscribeToSensorDataStream();
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();

    _unsubscribeFromSensorDataStream();
  }

  void _subscribeToSensorDataStream() {
    RawSensors().getSensorStream(widget.sensorType).then((Stream sensorStream) {
      _streamSubscription = sensorStream?.listen((dynamic data) {
        setState(() {
          _data = data;
        });
      });
    });
  }

  void _unsubscribeFromSensorDataStream() {
    _streamSubscription?.cancel();
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  rawsensors: ^0.0.3

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:rawsensors/rawsensors.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
16
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform android

Because of import path [package:rawsensors/rawsensors.dart] that declares support for platforms:

Package does not support Flutter platform ios

Because of import path [package:rawsensors/rawsensors.dart] that declares support for platforms:

Package does not support Flutter platform linux

Because of import path [package:rawsensors/rawsensors.dart] that declares support for platforms:

Package does not support Flutter platform macos

Because of import path [package:rawsensors/rawsensors.dart] that declares support for platforms:

Package does not support Flutter platform web

Because of import path [package:rawsensors/rawsensors.dart] that declares support for platforms:

Package does not support Flutter platform windows

Because of import path [package:rawsensors/rawsensors.dart] that declares support for platforms:

Package not compatible with SDK dart

because of import path [rawsensors] that is in a package requiring null.

Health suggestions

Format lib/rawsensors.dart.

Run flutter format to format lib/rawsensors.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

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