writeBloodOxygen method

Future<bool> writeBloodOxygen(
  1. double saturation,
  2. DateTime startTime,
  3. DateTime endTime, {
  4. double flowRate = 0.0,
})

Saves blood oxygen saturation record into Apple Health or Google Fit/Health Connect.

Returns true if successful, false otherwise.

Parameters:

  • saturation - the saturation of the blood oxygen in percentage
  • flowRate - optional supplemental oxygen flow rate, only supported on Google Fit (default 0.0)
  • startTime - the start time when this value is measured.
    • It must be equal to or earlier than endTime.
  • endTime - the end time when this value is measured.
    • It must be equal to or later than startTime.
    • Simply set endTime equal to startTime if the blood oxygen saturation is measured only at a specific point in time.

Implementation

Future<bool> writeBloodOxygen(
    double saturation, DateTime startTime, DateTime endTime,
    {double flowRate = 0.0}) async {
  if (startTime.isAfter(endTime))
    throw ArgumentError("startTime must be equal or earlier than endTime");
  bool? success;

  if (_platformType == PlatformType.IOS) {
    success = await writeHealthData(
        saturation, HealthDataType.BLOOD_OXYGEN, startTime, endTime);
  } else if (_platformType == PlatformType.ANDROID) {
    Map<String, dynamic> args = {
      'value': saturation,
      'flowRate': flowRate,
      'startTime': startTime.millisecondsSinceEpoch,
      'endTime': endTime.millisecondsSinceEpoch,
      'dataTypeKey': HealthDataType.BLOOD_OXYGEN.name,
    };
    success = await _channel.invokeMethod('writeBloodOxygen', args);
  }
  return success ?? false;
}