writeAudiogram method
Saves audiogram into Apple Health.
Returns true if successful, false otherwise.
Parameters:
frequencies
- array of frequencies of the testleftEarSensitivities
threshold in decibel for the left earrightEarSensitivities
threshold in decibel for the left earstartTime
- the start time when the audiogram is measured.- It must be equal to or earlier than
endTime
.
- It must be equal to or earlier than
endTime
- the end time when the audiogram is measured.- It must be equal to or later than
startTime
. - Simply set
endTime
equal tostartTime
if the audiogram is measured only at a specific point in time.
- It must be equal to or later than
metadata
- optional map of keys, both HKMetadataKeyExternalUUID and HKMetadataKeyDeviceName are required
Implementation
Future<bool> writeAudiogram(
List<double> frequencies,
List<double> leftEarSensitivities,
List<double> rightEarSensitivities,
DateTime startTime,
DateTime endTime,
{Map<String, dynamic>? metadata}) async {
if (frequencies.isEmpty ||
leftEarSensitivities.isEmpty ||
rightEarSensitivities.isEmpty)
throw ArgumentError(
"frequencies, leftEarSensitivities and rightEarSensitivities can't be empty");
if (frequencies.length != leftEarSensitivities.length ||
rightEarSensitivities.length != leftEarSensitivities.length)
throw ArgumentError(
"frequencies, leftEarSensitivities and rightEarSensitivities need to be of the same length");
if (startTime.isAfter(endTime))
throw ArgumentError("startTime must be equal or earlier than endTime");
if (_platformType == PlatformType.ANDROID)
throw UnsupportedError("writeAudiogram is not supported on Android");
Map<String, dynamic> args = {
'frequencies': frequencies,
'leftEarSensitivities': leftEarSensitivities,
'rightEarSensitivities': rightEarSensitivities,
'dataTypeKey': HealthDataType.AUDIOGRAM.name,
'startTime': startTime.millisecondsSinceEpoch,
'endTime': endTime.millisecondsSinceEpoch,
'metadata': metadata,
};
bool? success = await _channel.invokeMethod('writeAudiogram', args);
return success ?? false;
}