cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
527 stars 625 forks source link

[Health 10.2.0] Fetched data are not accurate #982

Open AdamBrejcak opened 2 weeks ago

AdamBrejcak commented 2 weeks ago

[Health 10.2.0] Fetched data are not accurate

Device / Emulator and OS

Describe the bug

I used my personal device for testing. let's say that i went for a walk in the morning at 8am and i did 5000 steps, and this is the only time i did some exercise for today, currently it's 10pm, the issue is when I call Health().getTotalStepsInInterval or even Health().getHealthIntervalDataFromTypes (with STEPS type and READ permission), with time window from 12pm until now (10pm), this will return some steps/value, this is not correct from my perspective as it should return 0 since in given time window i did NOT do any walking/steps

To Reproduce

Implement Health package as per documentation, then use any app which will track your steps (e.g. Samsung Health or Google Fit) make sure this app is allowed in google health connect, add walikng activity (or on physical device walk), in the morning for current day, then request steps from Health package by Health().getTotalStepsInInterval or even by Health().getHealthIntervalDataFrom but only for the afternoon today, see example below

        final List<HealthDataType> types = [HealthDataType.STEPS];
        final List<HealthDataAccess> permissions = [HealthDataAccess.READ];

        final DateTime now = DateTime.now();
        final DateTime noonToday = DateTime(now.year, now.month, now.day, 12);
        final DateTime midnightToday =
            DateTime(now.year, now.month, now.day, 23, 59);

        int? stepsFromInterval =
            await Health().getTotalStepsInInterval(noonToday, midnightToday);

        List<HealthDataPoint> stepsDataFromTypes = await Health()
            .getHealthDataFromTypes(
                types: types, startTime: noonToday, endTime: midnightToday);

Main idea here is that Health package should return 0 steps if there is no exercise done in given time window

Expected behavior

I would expect in this use case that getTotalStepsInInterval and also getHealthDataFromTypes to return 0 steps/value, since only exercise i did, was done before the time window that was passed in request

Actual behavior

getTotalStepsInInterval will return some steps/value, same with getHealthDataFromTypes (seems it's somehow calculated as average value for given day without considering when the exercise was done)

Flutter doctor -v

[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.22621.2428], locale sk-SK)
    • Flutter version 3.19.6 on channel stable at C:\Users\USER\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (8 weeks ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\USER\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2023.3)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11572160)

[√] VS Code (version 1.90.1)
    • VS Code at C:\Users\USER\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.90.0

[√] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 14 (API 34) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22621.2428]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 126.0.6478.61
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 125.0.2535.92

[√] Network resources
    • All expected network resources are available.