cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
547 stars 671 forks source link

[Health] Could not cast value of type 'HKWorkoutType' to 'HKCategoryType' #526

Closed pzierahn closed 2 years ago

pzierahn commented 2 years ago

Remember to specify the plugin name in the title!

Device / Emulator and OS

Please complete the following information for each phone and/or emulator you're experiencing this bug on:

Describe the bug

App crash when saving Workout health data.

To Reproduce

final start = DateTime.now();
bool success = await health.writeHealthData(
    50,
    HealthDataType.WORKOUT,
    start,
    start.add(const Duration(minutes: 50)),
);

Expected behavior

Store the workout.

Actual behavior

The iOS app crashes with the following output:

Could not cast value of type 'HKWorkoutType' (0x7fff87180cd8) to 'HKCategoryType' (0x7fff87180c10).
Lost connection to device.

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 2.12.0-4.1.pre, on macOS 12.3 21E230 darwin-x64, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] IntelliJ IDEA Community Edition (version 2021.3.3)
[✓] VS Code (version 1.65.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

Additional information

The problem seems to be similar to https://github.com/cph-cachet/flutter-plugins/issues/463.

JanBrin commented 2 years ago

Having the same issue. Any update to this?

crystalstorm commented 2 years ago

@JanBrin & @pzierahn I made a fix here: #544

MadsVSChristensen commented 2 years ago

Hey @pzierahn

Health has been updated to 4.0.0 and has support for adding workouts on Android and iOS using the writeWorkoutData instead and users should now use this function for workouts. However, due to the nature of the enums HealthDataType I will add an exception to the writeHealthData if uses try to add workouts using this function.

Best regards, Mads