motion_sensors 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • new60

motion_sensors #

Flutter plugin for accessing the Android and iOS accelerometer gyroscope and magnetometer sensors.

Getting Started #

To use this plugin, add motion_sensors as a dependency in your pubspec.yaml file.

import 'package:motion_sensors/motion_sensors.dart';

motionSensors.magnetometer.listen((MagnetometerEvent event) {
    print(event);
});

0.0.1 #

  • initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart' hide Colors;
import 'package:motion_sensors/motion_sensors.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Vector3 _accelerometer = Vector3.zero();
  Vector3 _gyroscope = Vector3.zero();
  Vector3 _magnetometer = Vector3.zero();
  Vector3 _userAaccelerometer = Vector3.zero();
  Vector3 _orientation = Vector3.zero();

  @override
  void initState() {
    super.initState();
    motionSensors.gyroscope.listen((GyroscopeEvent event) {
      setState(() {
        _gyroscope.setValues(event.x, event.y, event.z);
      });
    });
    motionSensors.accelerometer.listen((AccelerometerEvent event) {
      setState(() {
        _accelerometer.setValues(event.x, event.y, event.z);
      });
    });
    motionSensors.userAccelerometer.listen((UserAccelerometerEvent event) {
      setState(() {
        _userAaccelerometer.setValues(event.x, event.y, event.z);
      });
    });
    motionSensors.magnetometer.listen((MagnetometerEvent event) {
      setState(() {
        _magnetometer.setValues(event.x, event.y, event.z);
      });
    });
    motionSensors.orientation.listen((OrientationEvent event) {
      setState(() {
        _orientation.setValues(event.yaw, event.pitch, event.roll);
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Motion Sensors'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text('magnetometer'),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                Text('${_magnetometer.x.toStringAsFixed(4)}'),
                Text('${_magnetometer.y.toStringAsFixed(4)}'),
                Text('${_magnetometer.z.toStringAsFixed(4)}'),
              ],
            ),
            Text('gyroscope'),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                Text('${_gyroscope.x.toStringAsFixed(4)}'),
                Text('${_gyroscope.y.toStringAsFixed(4)}'),
                Text('${_gyroscope.z.toStringAsFixed(4)}'),
              ],
            ),
            Text('accelerometer'),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                Text('${_accelerometer.x.toStringAsFixed(4)}'),
                Text('${_accelerometer.y.toStringAsFixed(4)}'),
                Text('${_accelerometer.z.toStringAsFixed(4)}'),
              ],
            ),
            Text('userAccelerometer'),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                Text('${_userAaccelerometer.x.toStringAsFixed(4)}'),
                Text('${_userAaccelerometer.y.toStringAsFixed(4)}'),
                Text('${_userAaccelerometer.z.toStringAsFixed(4)}'),
              ],
            ),
            Text('Orientation'),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: <Widget>[
                Text('${degrees(_orientation.x).toStringAsFixed(4)}'),
                Text('${degrees(_orientation.y).toStringAsFixed(4)}'),
                Text('${degrees(_orientation.z).toStringAsFixed(4)}'),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  motion_sensors: ^0.0.1

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

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:motion_sensors/motion_sensors.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:motion_sensors/motion_sensors.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:motion_sensors/motion_sensors.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:motion_sensors/motion_sensors.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • motion_sensors that is a package requiring null.

Health suggestions

Format lib/motion_sensors.dart.

Run flutter format to format lib/motion_sensors.dart.

Maintenance issues and suggestions

Use constrained dependencies. (-20 points)

The pubspec.yaml contains 1 dependency without version constraints. Specify version ranges for the following dependencies: vector_math.

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
vector_math any 2.0.8 2.1.0-nullsafety
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
Dev dependencies
flutter_test