Writing data
Write health and fitness data to Apple HealthKit on iOS and Health Connect on Android, with the write method that matches each data type.
The Health class provides a write method per kind of data. All write methods require WRITE permission for the types you write; see Permissions. For the full API, see the API reference on pub.dev.
Write methods
| Method | Data types | Use case | Guide |
|---|---|---|---|
writeHealthData | Most numeric types | General health metrics (weight, height, heart rate, blood glucose and so on) | Numeric data |
writeWorkoutData | WORKOUT | Exercise sessions with activity types | Workouts |
writeBloodPressure | BLOOD_PRESSURE_* | Systolic and diastolic readings | Blood pressure and oxygen |
writeBloodOxygen | BLOOD_OXYGEN | Blood oxygen saturation | Blood pressure and oxygen |
writeMeal | NUTRITION | Meals with macronutrients and micronutrients | Nutrition |
writeMenstruationFlow | MENSTRUATION_FLOW | Menstrual cycle tracking | Specialized types |
writeAudiogram | AUDIOGRAM | Hearing test results | Specialized types |
writeInsulinDelivery | INSULIN_DELIVERY | Insulin doses | Specialized types |
To remove data, see Deleting data.
Write flow
Request WRITE permission, then write the value. Each write method returns true on success.
Request write permission
Always request WRITE permission before you write. Pass one HealthDataAccess value per type:
Constraints and errors
- The start time must be less than or equal to the end time. Otherwise, the plugin throws an
ArgumentError. - WRITE is not allowed for ECG and event types:
ELECTROCARDIOGRAM,HIGH_HEART_RATE_EVENT,LOW_HEART_RATE_EVENT,IRREGULAR_HEART_RATE_EVENT,WALKING_HEART_RATEandATRIAL_FIBRILLATION_BURDEN. Requesting WRITE permission for these types throws. - On iOS,
recordingMethodmust bemanualorautomatic. - If the data type is not supported on the current platform, the plugin throws a
HealthException. - Workout activity types are platform-specific. The plugin validates the activity type and throws if it is not supported on the current platform.
- For sleep and headache types, the plugin ignores the value you pass and sets the correct categorical value automatically, based on the type.
Data validation
The plugin performs basic validation. The platform may also reject values:
Common patterns
Set the timestamp
Handle a failed write
A write returns false when it fails, for example because permission is missing:
Write several values
Quick reference
One call per write method. For details, follow the guide links in the Write methods table.
Generic write
Use writeHealthData for most numeric types. Units default per type, but you can provide one on iOS.
Workout
Blood pressure
Blood oxygen
Meal
writeMeal supports many micronutrients; pass the values you have.
Menstruation flow
Audiogram (iOS only)
Insulin delivery (iOS only)
Platform differences
- Requires the Health Connect SDK to be available.
- Write operations may return
falseif Health Connect is not installed. - Data syncs across connected apps.
- Some specialized types may have limited support.
- Your app cannot read data it wrote without READ permission.
- Write operations return
trueon success. - Data appears immediately in the Apple Health app.
- All value types are supported.