Installation
Add the health plugin to a Flutter app, configure it, and request permissions.
This page covers the dependency, initialization and permission requests. Platform-specific configuration is described in Android setup and iOS setup.
Add the dependency
pub.dev Local path pubspec.yaml If you use a published version instead of the local path, replace the path with the appropriate version constraint.
Initialize the plugin
Call
configure()once, before you use any other method:configure()looks up the ID thatdeviceIdreturns. On Android, this isBuild.ID, a build label that all devices with the same Android build share; on iOS, it is theidentifierForVendor. For testing, you can pass a customDeviceInfoPlugintoHealth().Request permissions when needed
Check which permissions are granted and request the missing ones:
requestAuthorization()throws anArgumentErrorwhen:permissionsandtypesdiffer in length;permissionsasks for WRITE or READ_WRITE access to one of six read-only iOS types:ELECTROCARDIOGRAM,HIGH_HEART_RATE_EVENT,LOW_HEART_RATE_EVENT,IRREGULAR_HEART_RATE_EVENT,WALKING_HEART_RATEorATRIAL_FIBRILLATION_BURDEN.
See Permissions for the full permission model.
Configure each platform
- Android: set
minSdkto 26 or later, makeMainActivityextendFlutterFragmentActivity, declare the Health Connect permissions, queries and privacy policy entries inAndroidManifest.xml, optionally enable history and background access, and handle the Health Connect install flow. - iOS: set the deployment target to iOS 15.0 or later, enable the HealthKit capability, and add
NSHealthShareUsageDescriptionandNSHealthUpdateUsageDescriptiontoInfo.plist.
- Android: set