You are reading the docs for Health13.x, an older version. Go to 14.x, the latest version.
Data points
Fetch individual health data points with full details using getHealthDataFromTypes.
Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor
getHealthDataFromTypes returns the individual data points of one or more types in a time range. Use it when you need raw measurements, timelines or exports. For bucketed or summarized data, see Interval data.
The method returns a List<HealthDataPoint> of raw data points from the native health platform, passed through removeDuplicates; see Remove duplicates.
The plugin reads the types one after another, so the points of each type follow each other in the order of types. Within a type, Android returns the oldest points first, and iOS the newest first, with ECGs and workout routes in no fixed order.
On Android, a type without READ permission, or a read that Health Connect refuses, adds no points instead of throwing an error.
Each HealthDataPoint has these fields:
Field
Description
uuid
Health Connect record ID on Android, shared by the points of one record; HealthKit sample UUID on iOS
value
Health value (numeric, workout, audiogram and so on)
final heartRatePoints = await health.getHealthDataFromTypes( types: [HealthDataType.HEART_RATE], startTime: DateTime.now().subtract(Duration(hours: 24)), endTime: DateTime.now(),);print('Found ${heartRatePoints.length} heart rate measurements');for (var point in heartRatePoints) { final value = (point.value as NumericHealthValue).numericValue; print('Heart rate: $value ${point.unit.name} at ${point.dateTo}');}
preferredUnits sets the unit of each type's values. The platforms convert different units:
Platform
Conversions
Android
WEIGHT to POUND, HEIGHT to CENTIMETER or INCH, BODY_TEMPERATURE and SKIN_TEMPERATURE to DEGREE_FAHRENHEIT or KELVIN, and BLOOD_GLUCOSE to MILLIMOLES_PER_LITER
iOS
Any unit that HealthKit can convert a quantity type to, except CENTIMETER and MILLIMOLES_PER_LITER
On iOS, you can request data in specific units:
final data = await health.getHealthDataFromTypes( types: [ HealthDataType.HEIGHT, HealthDataType.WEIGHT, HealthDataType.DISTANCE_WALKING_RUNNING, ], startTime: start, endTime: end, preferredUnits: { HealthDataType.HEIGHT: HealthDataUnit.INCH, // Instead of meters HealthDataType.WEIGHT: HealthDataUnit.POUND, // Instead of kg HealthDataType.DISTANCE_WALKING_RUNNING: HealthDataUnit.MILE, // Instead of meters },);
Unsupported units
On Android, any other unit leaves the value in the default unit, but sets the point's unit to the unit you requested. On iOS, any other unit for a quantity type, such as HEIGHT, crashes the app when the time range holds data. Request only the conversions in the table.
To convert values in your app instead, map between HealthDataUnit values:
double convertUnit( double value, HealthDataUnit from, HealthDataUnit to,) { // Weight conversions if (from == HealthDataUnit.KILOGRAM && to == HealthDataUnit.POUND) { return value * 2.20462; } if (from == HealthDataUnit.POUND && to == HealthDataUnit.KILOGRAM) { return value / 2.20462; } // Length conversions if (from == HealthDataUnit.CENTIMETER && to == HealthDataUnit.INCH) { return value / 2.54; } if (from == HealthDataUnit.INCH && to == HealthDataUnit.CENTIMETER) { return value * 2.54; } // Temperature conversions if (from == HealthDataUnit.DEGREE_CELSIUS && to == HealthDataUnit.DEGREE_FAHRENHEIT) { return (value * 9/5) + 32; } if (from == HealthDataUnit.DEGREE_FAHRENHEIT && to == HealthDataUnit.DEGREE_CELSIUS) { return (value - 32) * 5/9; } return value;}
final data = await health.getHealthDataFromTypes( types: [HealthDataType.WEIGHT], startTime: start, endTime: end,);for (var point in data) { final numericValue = point.value as NumericHealthValue; print('Weight: ${numericValue.numericValue} ${point.unit.name}');}
final workouts = await health.getHealthDataFromTypes( types: [HealthDataType.WORKOUT], startTime: start, endTime: end,);for (var point in workouts) { final workout = point.value as WorkoutHealthValue; print('Activity: ${workout.workoutActivityType.name}'); print('Duration: ${point.dateTo.difference(point.dateFrom)}'); if (workout.totalEnergyBurned != null) { print('Calories: ${workout.totalEnergyBurned} ${workout.totalEnergyBurnedUnit?.name}'); } if (workout.totalDistance != null) { print('Distance: ${workout.totalDistance} ${workout.totalDistanceUnit?.name}'); } if (workout.totalSteps != null) { print('Steps: ${workout.totalSteps}'); } // Check workout summary if (point.workoutSummary != null) { print('Summary: ${point.workoutSummary}'); }}
On Android, the plugin sums totalDistance, totalEnergyBurned and totalSteps from the distance, total calories burned and steps records that all apps wrote during the workout. If Health Connect refuses one of these reads, the plugin returns no workouts. To read workouts on Android, also request READ access to DISTANCE_DELTA, TOTAL_CALORIES_BURNED and STEPS.
On iOS, the totals are the ones the workout stores, and totalSteps is always null.
final audiograms = await health.getHealthDataFromTypes( types: [HealthDataType.AUDIOGRAM], startTime: start, endTime: end,);for (var point in audiograms) { final audiogram = point.value as AudiogramHealthValue; print('Frequencies: ${audiogram.frequencies}'); print('Left ear: ${audiogram.leftEarSensitivities} dB'); print('Right ear: ${audiogram.rightEarSensitivities} dB');}
Known issue
health 13.x expects an audiogram to hold a threshold for both ears at every frequency. Reading an audiogram in which an ear was not tested at some frequency crashes the app. To read such audiograms, use health 14.x, which returns null for an untested ear.
class HealthStats { final int count; final double sum; final double mean; final double min; final double max; final double median; HealthStats({ required this.count, required this.sum, required this.mean, required this.min, required this.max, required this.median, }); HealthStats.empty() : count = 0, sum = 0, mean = 0, min = 0, max = 0, median = 0;}Future<HealthStats> calculateStats( List<HealthDataPoint> data,) async { if (data.isEmpty) { return HealthStats.empty(); } final values = data .map((p) => (p.value as NumericHealthValue).numericValue.toDouble()) .toList(); values.sort(); final sum = values.reduce((a, b) => a + b); final mean = sum / values.length; final min = values.first; final max = values.last; final median = values[values.length ~/ 2]; return HealthStats( count: values.length, sum: sum, mean: mean, min: min, max: max, median: median, );}// Usagefinal heartRate = await health.getHealthDataFromTypes( types: [HealthDataType.HEART_RATE], startTime: DateTime.now().subtract(Duration(days: 7)), endTime: DateTime.now(),);final stats = await calculateStats(heartRate);print('Average heart rate: ${stats.mean.toStringAsFixed(1)} BPM');print('Range: ${stats.min} - ${stats.max} BPM');
Map<DateTime, List<HealthDataPoint>> groupByDate( List<HealthDataPoint> data,) { final grouped = <DateTime, List<HealthDataPoint>>{}; for (var point in data) { final date = DateTime( point.dateTo.year, point.dateTo.month, point.dateTo.day, ); grouped.putIfAbsent(date, () => []).add(point); } return grouped;}// Usagefinal steps = await health.getHealthDataFromTypes( types: [HealthDataType.STEPS], startTime: DateTime.now().subtract(Duration(days: 30)), endTime: DateTime.now(),);final byDate = groupByDate(steps);for (var entry in byDate.entries) { final dailyTotal = entry.value .map((p) => (p.value as NumericHealthValue).numericValue) .reduce((a, b) => a + b); print('${entry.key.toLocal()}: $dailyTotal steps');}
Step points from several sources, such as a phone and a watch, may overlap, and a sum of raw points then counts those steps twice. Interval reads let the platform remove the overlap. For daily step totals, see Interval data.
On Android, the plugin computes BMI from weight and height. Requesting BODY_MASS_INDEX fetches weight and height automatically.
Each weight in the range gives one BMI point, computed with the latest height in the range. Without a height in the range, there are no BMI points.
// Requesting BMI automatically fetches weight and heightfinal bmiData = await health.getHealthDataFromTypes( types: [HealthDataType.BODY_MASS_INDEX], startTime: start, endTime: end,);// BMI is calculated using the latest height in the range// and all weight measurements in the range
On iOS, sleep types are converted to minutes automatically, based on the time range.
final sleep = await health.getHealthDataFromTypes( types: [ HealthDataType.SLEEP_ASLEEP, HealthDataType.SLEEP_AWAKE, HealthDataType.SLEEP_REM, HealthDataType.SLEEP_DEEP, ], startTime: DateTime.now().subtract(Duration(days: 1)), endTime: DateTime.now(),);for (var point in sleep) { final minutes = (point.value as NumericHealthValue).numericValue; print('${point.type.name}: ${minutes} minutes'); print(' From: ${point.dateFrom}'); print(' To: ${point.dateTo}');}