vitals library

Type-safe access to Apple Health and Health Connect.

final vitals = Vitals.instance;
await vitals.requestPermissions(
  const PermissionRequest(read: {VitalType.steps}),
);

final daily = await vitals.statistics(
  VitalType.steps,
  from: DateTime.now().subtract(const Duration(days: 30)),
  to: DateTime.now(),
  bucket: VitalBucket.daily,
);

Classes

Concentration
A blood glucose concentration, stored canonically in mmol/L.
ConcentrationSample
A blood glucose reading.
CountSample
A whole-number tally, such as steps or flights climbed.
DurationSample
A span of time, such as a mindfulness session.
Energy
An amount of energy, stored canonically in kilocalories.
EnergySample
An energy reading, such as calories burned.
FakeVitals
An in-memory Vitals for tests and previews.
Length
A distance, stored canonically in metres.
LengthSample
A distance reading.
Mass
A mass, stored canonically so the unit is never in doubt.
MassSample
A body mass reading.
MethodChannelVitals
Talks to HealthKit and Health Connect over a method channel.
PercentSample
A proportion, stored as a fraction from 0 to 1.
PermissionRequest
What was asked for, and what came back.
Pressure
A pressure, stored canonically in millimetres of mercury.
PressureSample
A blood pressure reading.
RateSample
A per-minute rate, such as heart rate or respiratory rate.
SleepSample
A stretch of sleep.
Temperature
A temperature, stored canonically in degrees Celsius.
TemperatureSample
A body temperature reading.
Vitals
Read and write health data.
VitalSample
A single recorded measurement.
VitalSource
Where a sample came from.
VitalsReadProbe
Why this package has no readAccess().
VitalStatistic
One reduced value covering a span of time.
VitalType<T extends VitalSample>
A kind of health data, carrying the Dart type it reads back as.
Volume
A volume, stored canonically in litres.
VolumeSample
A volume reading, such as water intake.
WorkoutSample
A recorded workout.

Enums

SleepStage
Stages of sleep, as both platforms model them.
VitalAggregate
How a series of samples is reduced into one number per bucket.
VitalBucket
How wide each statistics bucket is.
WriteAccess
Whether this app may write a given type.

Exceptions / Errors

AuthorizationNotDeterminedException
A query was made before the user was ever asked for access.
HealthDataUnavailableException
Health data is not usable on this device.
UnsupportedVitalTypeException
The requested type has no equivalent on this platform.
VitalsException
Base class for every failure this package raises.
VitalsPlatformException
Anything the platform reported that does not map to a specific case.
VitalsWriteException
The platform refused a write, usually because access was denied.