pedometer 1.0.0 pedometer: ^1.0.0 copied to clipboard
A pedometer plugin for probing the native pedometer. Works for both iOS and Android and is written in Swift/Java.
pedometer #
This plugin allows for continuous step counting using the built-in pedometer sensor API of iOS and Android devices.
When the application is started the step count is set to 0, and every time a step count update is registrered, the cumulative step count value since the app was started will be returned. The update frequency depends on the platform; iOS updates less frequently than Android.
Permissions for Android #
No configuration needed.
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.