Pedometer with Daily steps counter using flutter

8.2k Views Asked by At

I am trying to build a basic fitness app using flutter. The app has two main features:

  1. Daily steps counter
  2. graph of historical data (number of steps each day)

I use the pedometer plugin to retrieve data from the sensors of the phone. My problem is that the plugin can only send the continuous step counting since the last reboot that means if the user does not open my app for serval days, I don't know how many steps he walked each day only the total number of steps he did. I thought about letting my app run in the background but it will be a waste of battery

P.s I read Implementing pedometer in flutter article by Masky, but it is not solving my problem.

Thanks for any kind of help :)

1

There are 1 best solutions below

3
On

Excerpt from: https://hub.packtpub.com/step-detector-and-step-counters-sensors/

The event timestamp represents the time at which the last step was taken. This sensor is especially useful for those applications that don’t want to run in the background and maintain the history of steps themselves. This sensor works in batches and in continuous mode.

Of the returned SensorEvent, the 1st value represents the number of steps since the last boot and it also contains a timestamp which is the amount of nanoseconds elapsed from the time of last device boot.

This site advises to use JobScheduler to "schedule periodic job to retrieve the total step count under suitable interval."

On the first site it explains how to maintain step history in case that's what you want, there's also sample code there.