Pedometer with Daily steps counter using flutter
Asked Answered
P

1

6

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 :)

Premer answered 22/5, 2021 at 19:25 Comment(5)
If you don't let a process run in the background then how are you supposed to know what's happening when the app is closed? If running in the background is a problem then you don't have to know how many steps he's been walking when the app was closed - it's a waste of battery.Jit
I thought maybe there is a way to get the number of steps by date from the sensorsPremer
There is a way to do that without running in the background.Jit
Can you share the way to do that with me? @un-indexPremer
I'm in the process of formulating an answer.Jit
J
1

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.

Jit answered 22/5, 2021 at 19:42 Comment(3)
Thanks for the answer, I am looking for something similar in flutterPremer
hey did you find it?Lungan
nope, I did notJit

© 2022 - 2024 — McMap. All rights reserved.