Choose a read method for raw data points, time buckets, aggregates or step totals, then filter, sort and process the results.
Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor
The Health class provides four read methods with different levels of granularity and aggregation. Before you read, call configure() and request authorization for the types you read; see Permissions. For the full API, see the API reference on pub.dev.
Data points
getHealthDataFromTypes fetches individual data points for a time range. Use it for detailed raw data, individual measurements, timelines and export or backup.
Interval data
getHealthIntervalDataFromTypes aggregates data into fixed time intervals, such as hourly or daily. Use it for charts, daily, weekly or monthly summaries, trend analysis and statistical overviews.
Aggregate data
getHealthAggregateDataFromTypes fetches pre-aggregated summaries across multiple types. Use it for workout summaries, multi-metric dashboards, performance analytics and activity overviews.
Step totals
getTotalStepsInInterval returns the total step count for a period. Use it for step counters, daily step goals, quick step queries and activity badges.
// 1. Configure Healthawait health.configure();// 2. Request permissionsawait health.requestAuthorization([HealthDataType.STEPS]);// 3. Choose reading method based on use casefinal data = await health.getHealthDataFromTypes( types: [HealthDataType.STEPS], startTime: DateTime.now().subtract(Duration(hours: 24)), endTime: DateTime.now(),);// 4. Process resultsfor (var point in data) { print('${point.type}: ${point.value} ${point.unit}');}
getHealthDataFromTypes also accepts a recording-method filter and, per type, a preferred unit. Preferred units apply on iOS only; see Request preferred units (iOS).
final points = await health.getHealthDataFromTypes( types: [ HealthDataType.HEART_RATE, HealthDataType.STEPS, ], startTime: start, endTime: end, // Optional: filter out entries by recording method recordingMethodsToFilter: const [ // RecordingMethod.manual, ], // Optional: request a specific unit per type preferredUnits: { HealthDataType.HEIGHT: HealthDataUnit.METER, },);
// Sort by date (newest first)data.sort((a, b) => b.dateTo.compareTo(a.dateTo));// Sort by date (oldest first)data.sort((a, b) => a.dateTo.compareTo(b.dateTo));// Sort by valuedata.sort((a, b) { final aValue = (a.value as NumericHealthValue).numericValue; final bValue = (b.value as NumericHealthValue).numericValue; return bValue.compareTo(aValue);});
void processHealthValue(HealthDataPoint point) { final value = point.value; if (value is NumericHealthValue) { print('Numeric: ${value.numericValue}'); } else if (value is WorkoutHealthValue) { print('Workout: ${value.workoutActivityType.name}'); } else if (value is NutritionHealthValue) { print('Meal: ${value.name}'); } else if (value is AudiogramHealthValue) { print('Audiogram: ${value.frequencies.length} frequencies'); } else if (value is ElectrocardiogramHealthValue) { print('ECG: ${value.averageHeartRate} bpm'); } else if (value is InsulinDeliveryHealthValue) { print('Insulin: ${value.units} units'); } else if (value is MenstruationFlowHealthValue) { print('Flow: ${value.flow.name}'); }}