delete method

Future<bool> delete({
  1. required HealthDataType type,
  2. required DateTime startTime,
  3. DateTime? endTime,
})

Deletes all records of the given type for a given period of time.

Returns true if successful, false otherwise.

Parameters:

  • type - the value's HealthDataType.
  • startTime - the start time when this value is measured. Must be equal to or earlier than endTime.
  • endTime - the end time when this value is measured. Must be equal to or later than startTime.

Implementation

Future<bool> delete({
  required HealthDataType type,
  required DateTime startTime,
  DateTime? endTime,
}) async {
  endTime ??= startTime;
  if (startTime.isAfter(endTime)) {
    throw ArgumentError("startTime must be equal or earlier than endTime");
  }

  Map<String, dynamic> args = {
    'dataTypeKey': type.name,
    'startTime': startTime.millisecondsSinceEpoch,
    'endTime': endTime.millisecondsSinceEpoch
  };
  bool? success = await _channel.invokeMethod('delete', args);
  return success ?? false;
}