Skip to content

Writing & deleting data

Use writeHealthData for most numerical types. Units default per type but can be provided on iOS.

final ok = await health.writeHealthData(
value: 70,
type: HealthDataType.HEART_RATE,
startTime: start,
endTime: end,
recordingMethod: RecordingMethod.manual, // iOS: only manual/automatic
);

Values for Sleep and Headache types are ignored; the plugin sets the correct categorical value automatically based on the type.

final ok = await health.writeWorkoutData(
activityType: HealthWorkoutActivityType.RUNNING,
start: start,
end: end,
totalEnergyBurned: 400, // kcal (iOS)
totalDistance: 3000, // meter (iOS)
title: 'Evening run', // used on Android Health Connect
recordingMethod: RecordingMethod.automatic,
);
  • Activity types are platform-specific. The plugin validates and throws if unsupported on the current platform.
await health.writeBloodPressure(
systolic: 120,
diastolic: 80,
startTime: time,
clientRecordId: 'my-id-1', // optional
clientRecordVersion: 1.0, // optional
);
await health.writeBloodOxygen(
saturation: 98.0,
startTime: time,
recordingMethod: RecordingMethod.automatic,
);
await health.writeMeal(
mealType: MealType.DINNER,
startTime: start,
endTime: end,
name: 'Pasta',
caloriesConsumed: 850,
protein: 32,
fatTotal: 28,
carbohydrates: 110,
// ...many micronutrients supported; pass what you have
);
await health.writeMenstruationFlow(
flow: MenstrualFlow.medium,
isStartOfCycle: true,
startTime: start,
endTime: end,
);
await health.writeAudiogram(
frequencies: [125, 500, 1000, 2000, 4000, 8000],
leftEarSensitivities: [49, 54, 89, 52, 77, 35],
rightEarSensitivities: [76, 66, 90, 22, 85, 45],
startTime: start,
endTime: end,
metadata: {
'HKExternalUUID': 'your-id',
'HKDeviceName': 'device name',
},
);
await health.writeInsulinDelivery(
5.0,
InsulinDeliveryReason.BOLUS,
start,
end,
);

Delete by type and interval:

await health.delete(
type: HealthDataType.STEPS,
startTime: start,
endTime: end,
);

Delete a specific record by UUID:

await health.deleteByUUID(
uuid: 'A91A2F10-3D7B-486A-B140-5ADCD3C9C6D0',
type: HealthDataType.WORKOUT, // required on iOS
);

Delete by client record id (Android Health Connect):

await health.deleteByClientRecordId(
dataTypeKey: HealthDataType.ACTIVE_ENERGY_BURNED,
clientRecordId: 'my-id-1',
);
  • Start time must be less than or equal to end time (<=); otherwise an ArgumentError is thrown.
  • For ECG/events (ELECTROCARDIOGRAM, HIGH_HEART_RATE_EVENT, LOW_HEART_RATE_EVENT, IRREGULAR_HEART_RATE_EVENT, WALKING_HEART_RATE, ATRIAL_FIBRILLATION_BURDEN), WRITE is not allowed; requesting WRITE permissions throws.
  • On iOS, recordingMethod must be manual or automatic.
  • If the data type is not supported on the current platform, a HealthException is thrown.