kidd3166 e3eb02df8a 1.4 update | преди 2 години | |
---|---|---|
.. | ||
android | преди 2 години | |
example | преди 3 години | |
imgs | преди 3 години | |
ios | преди 3 години | |
lib | преди 3 години | |
test | преди 3 години | |
.metadata | преди 3 години | |
CHANGELOG.md | преди 3 години | |
LICENSE | преди 3 години | |
README.md | преди 3 години | |
pubspec.yaml | преди 3 години |
This plugin allows for continuous step counting and pedestrian status using the built-in pedometer sensor API of iOS and Android devices.
For Android 10 and above add the following permission to the Android manifest:
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
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>
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.
The Pedestrian status is either walking
or stopped
. In the case that of an error,
the status will be unknown
.
Both Step Count and Pedestrian Status may not be available on some phones:
There is nothing we can do to solve this problem, unfortunately.
In the case that a sensor is not available, an error will be thrown. It is important that you handle this error yourself.
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.
Stream<StepCount> _stepCountStream;
Stream<PedestrianStatus> _pedestrianStatusStream;
void onStepCount(StepCount event) {
/// Handle step count changed
int steps = event.steps;
DateTime timeStamp = event.timeStamp;
}
void onPedestrianStatusChanged(PedestrianStatus event) {
/// Handle status changed
String status = event.status;
DateTime timeStamp = event.timeStamp;
}
void onPedestrianStatusError(error) {
/// Handle the error
}
void onStepCountError(error) {
/// Handle the 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);
...
}