Flutter-Steps-Tracker
Flutter-Steps-Tracker copied to clipboard
Daily steps
Hi @TarekAlabd,
To get the daily steps, I think it is better to get the new steps only, and accumulate them on the steps today, this method allows not to depend on the phone date and leave the date assignment for the back end service. Or use any local storage service to accumulate depending on the device date.
Code snippet from my repo:
class PedometerService {
PedometerService();
// pedometer package returns the steps taken since last system boot.
// so we use this var for get only new steps
int _lastCount = 0;
// call it before start listening to newSteps
Future<void> init() async {
_lastCount =
await Pedometer.stepCountStream.first.then((value) => value.steps);
}
Stream<int> get newSteps {
return Pedometer.stepCountStream.map(
(event) {
final newSteps = event.steps - _lastCount;
_lastCount = event.steps;
return newSteps;
},
).where(
(e) => e != 0,
);
}
}
I hope this helps you.
i would like to contribute to this issue... kindly assign me i am GSSOC'24 contributor