cph-cachet / flutter-plugins

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

[Health 5.0.0] supplemental_oxygen_flow_rate not set (Google Fit) #694

Closed maxiaodegithub closed 1 year ago

maxiaodegithub commented 1 year 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:

NB: Bugs pertaining to old devices/OS versions will likely not be fixed.

Describe the bug

health: ^5.0.0 and health: ^4.4.0 Error reported when writing blood oxygen

PlatformException(error, supplemental_oxygen_flow_rate not set, null, java.lang.IllegalArgumentException: supplemental_oxygen_flow_rate not set

bool success = await health.writeHealthData( value / 100, HealthDataType.BLOOD_OXYGEN, time, time,);

hoffmatteo commented 1 year ago

This bug will be fixed in the upcoming release. For now, a temporary fix can be applied by setting the supplemental oxygen flow rate to the default of zero: https://github.com/cph-cachet/flutter-plugins/blob/d6c5941ef9425b0c4cb03bcf6c4aa5d8f7432ab4/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt#L618-L622

    // ...
    // temporary fix
    val isOxygen = field == HealthFields.FIELD_OXYGEN_SATURATION
    if (isOxygen) {
      builder.setField(HealthFields.FIELD_SUPPLEMENTAL_OXYGEN_FLOW_RATE, 0.0f)
    }
    // existing code
    val dataPoint = if (!isIntField(dataSource, field))
      builder.setField(field, (if (!isGlucose) value else (value / MMOLL_2_MGDL).toFloat()))
        .build() else 
      builder.setField(field, value.toInt()).build()
    // ...