Skip to content
GUIDE · UNIFIED WORKFLOW

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

ShapeDescriptionExamples
InstantOne measurement at one timeWeight, blood glucose, temperature
IntervalAn event spanning a durationSteps, sleep session, exercise session
SeriesTimestamped samples inside an intervalHeart rate, speed, cycling cadence

Instant record

dart
final weight = WeightRecord(
  id: HealthRecordId.none,
  time: DateTime.now(),
  zoneOffsetSeconds: 3600,
  weight: Mass.kilograms(72.5),
  metadata: Metadata.manualEntry(),
);

Interval record

dart
final steps = StepsRecord(
  id: HealthRecordId.none,
  startTime: start,
  endTime: end,
  startZoneOffsetSeconds: 3600,
  endZoneOffsetSeconds: 3600,
  count: Number(1500),
  metadata: Metadata.automaticallyRecorded(),
);

Series record

dart
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.

dart
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.
  • Device details 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.

Released under the Apache 2.0 License.