writeBloodOxygen method

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

Saves blood oxygen saturation record.

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 saturation is measured. Must be equal to or earlier than endTime.
  • endTime - the end time when this saturation is measured. 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 (default).

Implementation

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

  if (Platform.isIOS) {
    success = await writeHealthData(
        value: saturation,
        type: HealthDataType.BLOOD_OXYGEN,
        startTime: startTime,
        endTime: endTime);
  } else if (Platform.isAndroid) {
    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;
}