cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
550 stars 680 forks source link

[Health] Crash when executing writeWorkoutData #553

Closed JanBrin closed 2 years ago

JanBrin commented 2 years ago

Device / Emulator and OS

Describe the bug

When executing the below code the App crashes with error message "Invalid Arguments - ActivityType, startTime or endTime invalid".

To Reproduce

    List<HealthDataType> types = [HealthDataType.WORKOUT];
    List<HealthDataAccess> accesses = [HealthDataAccess.WRITE];
    bool? hasPerms =
        await HealthFactory.hasPermissions(types, permissions: accesses);
    if (hasPerms == true) {
      HealthFactory health = HealthFactory();
      final now = DateTime.now();
      final earlier = now.subtract(Duration(seconds: seconds));
      await health.writeWorkoutData(HealthWorkoutActivityType.WEIGHTLIFTING, earlier, now);
    }

Expected behavior

I would expect it to not crash and write the workout to health.

Actual behavior

The app crashes with error message "Invalid Arguments - ActivityType, startTime or endTime invalid".

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.4 21F79 darwin-arm, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.1.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
MadsVSChristensen commented 2 years ago

Hey @JanBrin

As the documentation shows, the WEIGHTLIFTING type is only on Android, hence using it on iOS would not produce any result.

I will add a check for the operating system and the type for a future release to avoid confusion.

Best regards, Mads