Aggregate data
How getHealthAggregateDataFromTypes fails on both platforms in health 13.x, and the read methods to use instead.
getHealthAggregateDataFromTypes is meant to return aggregate summaries across multiple types in one call, such as workouts with their energy and distance.
Known issue
getHealthAggregateDataFromTypes does not work in health 13.x: the Android handler expects different arguments, and iOS has no native handler for it. Every call throws, so the method never returns data. Use getHealthIntervalDataFromTypes for values per time interval, such as daily step totals, and getHealthDataFromTypes for workouts.
Signature
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
types | List<HealthDataType> | Yes | - | Health data types to query |
startDate | DateTime | Yes | - | Start of time range |
endDate | DateTime | Yes | - | End of time range |
activitySegmentDuration | int | No | 1 | Not used: neither platform reads it |
includeManualEntry | bool | No | true | Not used: neither platform reads it |
Read workout summaries
Read workouts with getHealthDataFromTypes instead. Each WORKOUT point holds a WorkoutHealthValue with the workout's totals:
For how each platform computes the totals, see Workout values.
Activity segment duration
activitySegmentDuration has no effect, and no read method in health 13.x splits workouts into segments. To read a quantity type, such as STEPS or ACTIVE_ENERGY_BURNED, in fixed time buckets, see Interval data.
Filter manual entries
includeManualEntry has no effect. To leave out manually entered workouts, pass recordingMethodsToFilter: [RecordingMethod.manual] to getHealthDataFromTypes:
Query multiple types
Query several related metrics at once with getHealthDataFromTypes. It returns the individual points of each type, not summaries:
Examples
The examples read workouts with getHealthDataFromTypes, which works on both platforms.
Workout dashboard
Activity type breakdown
Platform differences
The call fails on both platforms, with a different exception on each:
- When Health Connect is not available, the call throws an
UnsupportedError. - A type that the plugin does not support on Android, such as
DISTANCE_WALKING_RUNNING, throws aHealthException. - Otherwise, the native handler fails, because it reads the
dataTypeKeyandintervalarguments of an interval read, which this call does not send. The call throws aPlatformException. - For workouts,
getHealthDataFromTypessums the distance, total calories burned and steps that all apps recorded during each workout.
- A type that the plugin does not support on iOS, such as
DISTANCE_DELTA, throws aHealthException. - Otherwise, the call throws a
MissingPluginException, because the plugin has no native handler for it. - For workouts,
getHealthDataFromTypesreturns the energy and distance totals that each workout stores, and no step total.
Related
- Data points: individual data points
- Interval data: time-bucketed data
- Writing workouts: create workout data