Health records
The data model connects three concepts: records describe health events, measurement units carry values safely, and health data types describe supported operations.
Record shapes
| Shape | Description | Examples |
|---|---|---|
| Instant | One measurement at one time | Weight, blood glucose, temperature |
| Interval | An event spanning a duration | Steps, sleep session, exercise session |
| Series | Timestamped samples inside an interval | Heart rate, speed, cycling cadence |
Instant record
final weight = WeightRecord(
id: HealthRecordId.none,
time: DateTime.now(),
zoneOffsetSeconds: 3600,
weight: Mass.kilograms(72.5),
metadata: Metadata.manualEntry(),
);Interval record
final steps = StepsRecord(
id: HealthRecordId.none,
startTime: start,
endTime: end,
startZoneOffsetSeconds: 3600,
endZoneOffsetSeconds: 3600,
count: Number(1500),
metadata: Metadata.automaticallyRecorded(),
);Series record
final heartRate = HeartRateSeriesRecord(
id: HealthRecordId.none,
startTime: start,
endTime: end,
samples: [
HeartRateSample(time: start, rate: Frequency.perMinute(65)),
HeartRateSample(time: end, rate: Frequency.perMinute(80)),
],
metadata: Metadata.automaticallyRecorded(),
);Measurement units
Values use immutable unit types that convert without losing their physical meaning.
final bodyMass = Mass.pounds(155.4);
print(bodyMass.inKilograms);
final distance = Length.miles(3.1);
print(distance.inKilometers);Common unit families include Mass, Energy, Frequency, Length, Volume, Temperature, Pressure, BloodGlucose, Percentage, Power, TimeDuration, and Velocity.
Metadata and identity
Use HealthRecordId.none for a new record. Records read from a platform store carry the platform-assigned identifier.
Metadata describes how and where a record was captured:
Metadata.manualEntry()for a user-entered value.Metadata.automaticallyRecorded()for device-generated data.Devicedetails for the recording source when required.
Data-type capabilities
A health data type advertises its supported operations through its Dart interfaces. This means an unsupported aggregate or write request fails at compile time when possible, not after deployment.
See the complete generated API reference on pub.dev.