pedometer 1.2.5 pedometer: ^1.2.5 copied to clipboard
A Pedometer plugin for streaming step count updates, for iOS and Android.
pedometer #
This plugin allows for continuous step counting using the built-in pedometer sensor API of iOS and Android devices.
The step count returned is the number of steps since the phone was last booted.
Permissions for Android #
For Android 10 and above add the following permission to the Android manifest:
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
Permissions for iOS #
Users of this plug-in will have to manually open XCode and configure a few settings manually, mostly pertaining to privacy settings and permissions due to the application collecting the user's movement data.
Step 0: #
Open the XCode project located at <your_project>/iOS/Runner.xcodeproj
Step 1: Set Capabilities #
Step 2: Configure your plist #
XCode Issue: Enabling @objc inference #
Any errors are only visible when running through XCode, unfortunately.
To use this plugin, add pedometer
as a dependency in your pubspec.yaml file.
Example Usage #
Pedometer _pedometer;
StreamSubscription<int> _subscription;
...
void onData(int stepCountValue) {
print(stepCountValue);
}
void startListening() {
_pedometer = new Pedometer();
_subscription = _pedometer.pedometerStream.listen(_onData,
onError: _onError, onDone: _onDone, cancelOnError: true);
}
void stopListening() {
_subscription.cancel();
}
void _onData(int stepCountValue) async {
setState(() => _stepCountValue = "$stepCountValue");
}
void _onDone() => print("Finished pedometer tracking");
void _onError(error) => print("Flutter Pedometer Error: $error");
Consult the example-app for a concrete implementation.