dev-juyoung / Fitness

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.
MIT License
19 stars 11 forks source link

[Android] Error read step Fitness.read #9

Closed nongtiny closed 3 years ago

nongtiny commented 3 years ago

Hello.

First of all, Thanks for creating this library.

I found an issue. I can't catch errors in Fitness.read function. This makes the app stop.

I tried to get the Step start from 2021-06-02 23:05:00.000 to DateTime.now()

I already wrapped this function with try-catch, but it still can't catch the error.

When I tried to get the step from last midnight by using

final DateTime lastMidnight = new DateTime(now.year, now.month, now.day);

It works fine and returns an empty array.

Thanks in advance.

dev-juyoung commented 3 years ago

@nongtiny Thank you for using the Fitness plugin. Let's try it under the same conditions and see how we can fix the problem.

nongtiny commented 3 years ago

Thanks for your fast response.

It seems like if the GoogleFit doesn't have data from the start parameter it will fail.

I tried lastMidnight.subtract(const Duration(days: 2)). It also fail.

nongtiny commented 3 years ago

Now, I'm using timeUnit: TimeUnit.minutes. If I change to TimeUnit.days, it works fine.

dev-juyoung commented 3 years ago

@nongtiny Thank you for continuing to share the situation. Are you having the same problem when using "TimeUnit.minutes"?

nongtiny commented 3 years ago

Yes, I am.

Now, I have to fetch 2 times to make it works correctly. The first-time fetching is for past step data, it uses timeUnit : TimeUnit.days. The second time for today step. It uses timeUnit: TimeUnit.minutes