cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
548 stars 658 forks source link

[Health v4.5.0] Application crashes when I’m trying to write sleep data. #671

Open leonidlist opened 1 year ago

leonidlist commented 1 year ago

Device / Emulator and OS

Describe the bug

Can’t write sleep data, application crashes with error Could not cast value of type 'HKCategoryType' to 'HKQuantityType'.

To Reproduce

Try to write any sleep data

Expected behavior

Sleep data is written and app didn’t crash :D

Flutter doctor

[✓] Flutter (Channel stable, 3.3.9, on macOS 12.5 21G72 darwin-arm, locale en-PL)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.75.0)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

Additional information

I’m investigating it now, but it’s 100% related to this code block in SwiftHealthPlugin.swift

image
leonidlist commented 1 year ago

FYI: I’m trying to fix the issue so I’ll create a PR for that soon I guess

hayesOw commented 1 year ago

FYI: I’m trying to fix the issue so I’ll create a PR for that soon I guess

Hi, did you fix this?

hayesOw commented 1 year ago

I have raised a pr for this https://github.com/cph-cachet/flutter-plugins/pull/707/

samflink commented 1 year ago

Hi,

I recently upgraded from 3.4.4 to Health 6.0 and ran in the same issue. This looks very much like an issue I ran into with version 3.4.3 which has been solved in version 3.4.4 (see: https://github.com/cph-cachet/flutter-plugins/issues/500)

Since I cannot downgrade due to other plugin version dependencies, I temporarily solved the issue by adding these types to the SwiftHealthPlugin.swift:

    unitDict[SLEEP_IN_BED] = HKUnit.init(from: "")
    unitDict[SLEEP_ASLEEP] = HKUnit.init(from: "")
    unitDict[SLEEP_AWAKE] = HKUnit.init(from: "")

This at least solves the crash and saves the sleep session correctly.

Best regards,

Sam