pedometer
4.2.0A Pedometer and Step Detection package for Android and iOS. Step count is streamed as the platform updates it.
Readme
Pedometer
This plugin allows for continuous 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>
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<PedestrianStatus> _pedestrianStatusStream;
/// 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) {}
Future<void> initPlatformState() async {
// Init streams
_pedestrianStatusStream = await Pedometer.pedestrianStatusStream;
_stepCountStream = await Pedometer.stepCountStream;
// Listen to streams and handle errors
_stepCountStream.listen(onStepCount).onError(onStepCountError);
_pedestrianStatusStream
.listen(onPedestrianStatusChanged)
.onError(onPedestrianStatusError);
}
Changelog
4.2.0
- Update Kotlin version
- Update Gradle version
- Enabled SPM support for iOS
4.1.1
- upgrading kotlin version
- upgrading agp version
4.1.0
- upgrading gradle version
- upgrading agp version
- upgrading kotlin version
- changing gradle file structure
- untracking files on git
4.0.2
- Updates Kotlin plugin and AGP.
- Upgrade of
compileSdkVersionto 33. - Upgrade to Dart 3.
- Small updates to example app (asking for permissions)
3.0.0
- Migrated to null safety
2.1.0
- Removed automatic error handling such as when the sensor is not available. This allows the plugin user to see when errors occur.
2.0.2
- Getters for streams are no longer async
2.0.1+2
- Downgraded
minSdkVersionto 18 on Android - It was set to 26 by mistake in a previous release
2.0.1+1
- Fixed image link
2.0.1
- Added error handling for when sensors are unavailable
2.0.0
- Re-implemented the plugin for both Android and iOS
- This should solve many build problems which persisted on Android
- Added Pedestrian Status events and the ability to stream these
- Added a class for the already-existing step count event
1.2.5
- Android 10 and above requires the Activity Recognition permission, this has been added to the docs.
1.2.0
- The plugin now returns the steps taken since last boot up.
1.1.0
- The Pedometer stream now returns the value since the plugin was started on both platforms.
- Previously this was only the case on iOS, and Android returned the steps taken since last phone boot-up.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add pedometerpubspec.yaml
name: pedometer
description: A Pedometer and Step Detection package for Android and iOS. Step count is streamed as the platform updates it.
version: 4.2.0
homepage: https://github.com/cph-cachet/flutter-plugins
environment:
sdk: ">=3.8.0 <4.0.0"
flutter: ">=3.6.0"
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
config:
enable-swift-package-manager: true
plugin:
platforms:
android:
package: com.example.pedometer
pluginClass: PedometerPlugin
ios:
pluginClass: PedometerPlugin
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | On demand | Download | c7fcab13…5abda5 |
| 0.0.2 | On demand | Download | 49ac4866…2eeafe |
| 0.0.3 | On demand | Download | 20d7d1b9…52ad17 |
| 0.0.5 | On demand | Download | afe1f589…1ef6e7 |
| 1.0.0 | On demand | Download | ff8d0a23…940c48 |
| 1.1.0 | On demand | Download | 06cf0aa2…8f7dca |
| 1.2.0 | On demand | Download | 6e521482…5d9ed0 |
| 1.2.5 | On demand | Download | 02c3f2de…3cbbe5 |
| 2.0.0 | On demand | Download | 7d6f21eb…f089a5 |
| 2.0.1 | On demand | Download | 73a8fe39…3c8c29 |
| 2.0.1+1 | On demand | Download | 406b4285…381613 |
| 2.0.1+2 | On demand | Download | a7c8c730…496527 |
| 2.0.2 | On demand | Download | 54315026…0cb570 |
| 2.1.0 | On demand | Download | bc8b7899…e8f26d |
| 3.0.0 | On demand | Download | 16d7a3df…9957c1 |
| 4.0.0 | On demand | Download | 259f968b…2a0086 |
| 4.0.1 | On demand | Download | e8c574da…c54259 |
| 4.0.2 | On demand | Download | 11cfba2d…7969ee |
| 4.1.0 | On demand | Download | 46a31aea…fff967 |
| 4.1.1 | On demand | Download | 71e2608a…b00e1a |
| 4.2.0 | Cached · Upstream SHA-256 matched | Download | 146d9663…1a193d |
Dependencies
flutter {
"sdk": "flutter"
}