writeBloodOxygen method
Saves blood oxygen saturation record.
Returns true if successful, false otherwise.
Parameters:
saturation
- the saturation of the blood oxygen in percentageflowRate
- optional supplemental oxygen flow rate, only supported on Google Fit (default 0.0)startTime
- the start time when thissaturation
is measured. Must be equal to or earlier thanendTime
.endTime
- the end time when thissaturation
is measured. Must be equal to or later thanstartTime
. Simply setendTime
equal tostartTime
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;
}