cph-cachet / flutter-plugins

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

[Health 11.1.0] Missing WorkoutHealthValue register #1051

Open arodriguez1996 opened 1 month ago

arodriguez1996 commented 1 month ago

Device / Emulator and OS

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

Describe the bug

For any workout created by the Health app, you cannot use the fromJson method for the WorkoutHealthValue type because it is not registered in carp_serializable package.

To Reproduce

try to parce

 var entry = {uuid: A91A2F10-3D7B-486A-B140-5ADCD3C9C6D0, value: {__type: WorkoutHealthValue, workoutActivityType: RUNNING, totalEnergyBurned: 100, totalEnergyBurnedUnit: KILOCALORIE, totalDistance: 2000, totalDistanceUnit: METER}, type: WORKOUT, unit: NO_UNIT, dateFrom: 2024-09-24T17:34:00.000, dateTo: 2024-09-24T17:57:00.000, sourcePlatform: appleHealth, sourceDeviceId: 756B1A7A-C972-4BDB-9748-0D4749CF299C, sourceId: com.apple.Health, sourceName: Salud, recordingMethod: manual, workoutSummary: {workoutType: running, totalDistance: 2000, totalEnergyBurned: 100, totalSteps: 0}};

  HealthDataPoint.fromJson(entry);

Expected behavior

parse the json to HealthDataPoint entity

Actual behavior

  SerializationException - A 'fromJson' function was not found in the FromJsonFactory for the type 'WorkoutHealthValue'. Register a Serializable class using the 'FromJsonFactory().register()' method.
If you are using CARP Mobile Sensing, you can ensure json initialization by calling'CarpMobileSensing.ensureInitialized()' as part of your main method.

Stack trace: 
#0      FromJsonFactory.fromJson (package:carp_serializable/carp_serializable.dart:199:9)
#1      new HealthValue.fromJson (package:health/src/health_value_types.dart:11:25)
#2      _$HealthDataPointFromJson (package:health/health.g.dart:12:26)
#3      new HealthDataPoint.fromJson (package:health/src/health_data_point.dart:102:7)

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.24.3, on macOS 15.0 24A335 darwin-arm64, locale es-PE) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 16.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2023.1) [✓] VS Code (version 1.93.1) [✓] Connected device (4 available) [✓] Network resources

• No issues found!

malik19995 commented 1 month ago

Facing this issue on iOS 18 and health version 11.1.0.

Please review and merge asap.