Skip to content

API cheat sheet

Every method on HealthConnector, with the platform constraint that applies. Exact signatures live in the generated API docs.

Setup & status

CallStaticPlatformWhat it does
HealthConnector.create(config)YesBothBuilds the client for the current platform
HealthConnector.getHealthPlatformStatus()YesBothWhether a usable health store exists
HealthConnector.launchHealthAppPageInAppStore()YesAndroidSends the user to install or update Health Connect
dart
final status = await HealthConnector.getHealthPlatformStatus();
if (status != HealthPlatformStatus.available) return;

final connector = await HealthConnector.create();

Permissions

CallPlatformNotes
requestPermissions(permissions)BothiOS prompts once per data type, ever
getPermissionStatus(permission)BothiOS reads always return unknown
getGrantedPermissions()AndroidThrows UnsupportedOperationException on iOS
revokeAllPermissions()AndroidThrows UnsupportedOperationException on iOS

Features

CallPlatformNotes
getFeatureStatus(feature)BothiOS always returns available

Reading

CallReturnsNotes
readRecord(request)The record, or nullBuild with .readById(...)
readRecords(request)One page of recordsFollow nextPageRequest for the rest
readExerciseRoute(recordId)The route, or nullRequires the route permission

Writing & mutating

CallPlatformAtomicNotes
writeRecord(record)BothReturns the assigned HealthRecordId
writeRecords(records)BothYesMay mix record types
updateRecord(record)AndroidHealthKit records are immutable
updateRecords(records)AndroidYesSame constraint
deleteRecords(request)BothYesOnly records your app wrote

Aggregating & syncing

CallNotes
aggregate(request)Computed on device; result keeps its unit
synchronize(dataTypes:, syncToken:)syncToken: null sets a checkpoint; otherwise returns changes

Request builders on HealthDataType

BuilderProduces
.readPermission / .writePermissionA Permission
.readExerciseRoutePermission / .writeExerciseRoutePermissionRoute permissions (exercise session only)
.readById(id)A single-record read request
.readInTimeRange(startTime:, endTime:, pageSize:, sortDescriptor:)A paged read request
.deleteByIds(ids)A delete request
.deleteInTimeRange(startTime:, endTime:)A ranged delete request
.aggregateSum/Avg/Min/Max(startTime:, endTime:)An aggregate request, where the type supports it

Statuses and enums you will branch on

dart
HealthPlatformStatus.available        // and its unavailable variants
PermissionStatus.granted | denied | unknown
HealthPlatformFeatureStatus.available
SortDescriptor.timeAscending | timeDescending
HealthConnectorLogLevel.values

Exception hierarchy

text
HealthConnectorException
├── AuthorizationException              permission not granted
├── ConfigurationException              your manifest or Info.plist
├── HealthServiceUnavailableException   no usable store on this device
├── HealthServiceException              transient store failure — retry
├── InvalidArgumentException            bad input or expired sync token
├── UnsupportedOperationException       not on this platform or OS version
└── UnknownException                    unclassified

Each carries a HealthConnectorErrorCode — look any of them up in the error code reference.

Released under the Apache 2.0 License.