daily_pedometer2 1.1.3 copy "daily_pedometer2: ^1.1.3" to clipboard
daily_pedometer2: ^1.1.3 copied to clipboard

A Pedometer and Step Detection package for Android and iOS. Step count are daily and streamed as the platform updates it.

Pedometer #

THIS PACKAGE IS FORKED FROM https://pub.dartlang.org/packages/pedometer

pub package

This plugin allows for continuous step counting, daily step counting and pedestrian status using the built-in pedometer sensor API of iOS and Android devices.

Permissions #

For Android 10 and above add the following permission to the Android manifest:

<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

For iOS, add the following entries to your Info.plist file in the Runner xcode project:

<key>NSMotionUsageDescription</key>
<string>This application tracks your steps</string>
<key>UIBackgroundModes</key>
<array>
    <string>processing</string>
</array>

Daily Step Count #

The daily step count represents the number of steps taken in that day. On Android, any steps taken before installing the application will not be counted.

Step Count #

The step count represents the number of steps taken since the last system boot. On Android, any steps taken before installing the application will not be counted.

Pedestrian Status #

The Pedestrian status is either walking or stopped. In the case that of an error, the status will be unknown.

Availability of Sensors #

Both Step Count and Pedestrian Status may not be available on some phones:

  • It was found that some Samsung phones do not support Step Count or Pedestrian Status
  • Older iPhones do not support Pedestrian Status in particular

In the case that the step sensor is not available, an error will be thrown. The application needs to handle this error.

Example Usage #

See the example app for a fully-fledged example.

Below is shown a more generalized example. Remember to set the required permissions, as described above. This may require you to manually allow the permission in the "Settings" on the phone.

  Stream<StepCount> _stepCountStream;
  Stream<StepCount> _dailyStepCountStream;
  Stream<PedestrianStatus> _pedestrianStatusStream;

  /// Handle step count changed
  void onDailyStepCount(StepCount event) {
    int steps = event.steps;
    DateTime timeStamp = event.timeStamp;
  }

  /// Handle step count changed
  void onStepCount(StepCount event) {
    int steps = event.steps;
    DateTime timeStamp = event.timeStamp;
  }

  /// Handle status changed
  void onPedestrianStatusChanged(PedestrianStatus event) {
    String status = event.status;
    DateTime timeStamp = event.timeStamp;
  }

  /// Handle the error
  void onPedestrianStatusError(error) {}

  /// Handle the error
  void onStepCountError(error) {}

  /// Handle the error
  void onDailyStepCountError(error) {}

  Future<void> initPlatformState() async {
    // Init streams
    _pedestrianStatusStream = await Pedometer.pedestrianStatusStream;
    _stepCountStream = await Pedometer.stepCountStream;
    _dailyStepCountStream = await Pedometer.dailyStepCountStream;

    // Listen to streams and handle errors
    _stepCountStream.listen(onStepCount).onError(onStepCountError);

    _dailyStepCountStream
      .listen(onDailyStepCount)
      .onError(onDailyStepCountError);

    _pedestrianStatusStream
      .listen(onPedestrianStatusChanged)
      .onError(onPedestrianStatusError);
  }
5
likes
160
points
424
downloads

Publisher

verified publisherdomaxit.com

Weekly Downloads

A Pedometer and Step Detection package for Android and iOS. Step count are daily and streamed as the platform updates it.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on daily_pedometer2