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.
No configuration needed.
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.
Open the XCode project located at <your_project>/iOS/Runner.xcodeproj
Any errors are only visible when running through XCode, unfortunately.
To use this plugin, add pedometer
as a dependency in your pubspec.yaml file.
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.