how to fetch monthly steps data from google fit using health package flutter

454 Views Asked by At

Im writing a flutter program to receive the data from the google fit using the Health package,Im able to fetch weekly data as

       weeklyStepData = await health.getTotalStepsInInterval(
            now.subtract(const Duration(days: 7)), now);

But when i try to fetch the monthly data as

        final yesterday = now.subtract(Duration(days: 30));
    // var newDate = new DateTime(now.year, now.month, now.day - 29);
    monthlyStepData =
        await health.getTotalStepsInInterval(yesterday, now) ?? 0;

Its giving me exception "Caught exception in getTotalStepsInInterval: PlatformException(error, Must specify a valid minimum duration: -2134967296, null, java.lang.IllegalArgumentException: Must specify a valid minimum duration: -2134967296"

How to get the monthly steps data

1

There are 1 best solutions below

0
On

To get the monthly step data,we need to use the function getHealthDataFromTypes of health package. From the result we can filter only the stepdata ,remove duplicates and add all the values