You are reading the docs for Health13.x, an older version. Go to 14.x, the latest version.
Permissions
Request, check and revoke health data permissions on iOS and Android, including the Android runtime permissions.
Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor
Health data is sensitive. Both iOS and Android require explicit user consent before your app can read or write health data, and the user grants that consent separately for each data type.
Each type is requested with one of these access levels (HealthDataAccess):
At least one of the requested permissions is granted when the dialog closes. Permissions granted earlier count.
No requested permission is granted. It also returns false without a dialog when a type is not supported on Android. The same applies when no activity is attached, for example in a background task.
iOS
HealthKit handled the request, whether or not it showed the sheet and whatever the user chose.
HealthKit reported an error.
On Android, call hasPermissions() for each type to find out what the user granted. On iOS, HealthKit shows the sheet only when the request contains a type that the user has not answered yet.
requestAuthorization() throws an ArgumentError when permissions and types differ in length. On Android, it throws an UnsupportedError when Health Connect is not available. For the errors that read-only types cause, see Read-only types on iOS.
By default, requestAuthorization() requests READ access.
Choose the data types
final types = [ HealthDataType.STEPS, HealthDataType.HEART_RATE,];
Show the system permission dialog
final granted = await health.requestAuthorization(types);
Handle the response
if (granted) { // Start reading data await fetchHealthData();} else { // Show error message showPermissionError();}
The same flow as a complete function:
import 'package:health/health.dart';Future<void> requestStepsPermission() async { final health = Health(); await health.configure(); // Request permission to read steps final types = [HealthDataType.STEPS]; final granted = await health.requestAuthorization(types); // On iOS, true only means that HealthKit handled the request if (granted) { print('✓ Can now read step data!'); } else { print('✗ User denied permission'); }}
hasPermissions() checks whether your app already has permission, before you request or read data:
// Check if we can read stepsfinal types = [HealthDataType.STEPS];final hasPermission = await health.hasPermissions(types);if (hasPermission == true) { print('✓ We have permission!');} else { print('Need to request permission'); await health.requestAuthorization(types);}
Cannot be determined (iOS READ and READ_WRITE permissions).
Both platforms return false for a type they do not support. On iOS, hasPermissions() also returns false for GENDER, BLOOD_TYPE and BIRTH_DATE, even when the user granted access.
Note
On iOS, checking READ permissions returns null for privacy reasons. When you get null, assume that you need to request the permission.
The plugin requests and checks only Health Connect permissions. Health Connect needs no other Android runtime permission to read or write health data. Steps, distance and workouts do not need ACTIVITY_RECOGNITION or a location permission.
Request a location permission only when your app collects GPS positions itself, for example for insertWorkoutRouteData(). Request it with the permission_handler package:
import 'package:permission_handler/permission_handler.dart';Future<bool> requestLocationPermission() async { final status = await Permission.location.request(); return status.isGranted;}// Use before you record a workout routeawait requestLocationPermission();await health.requestAuthorization( [HealthDataType.WORKOUT, HealthDataType.WORKOUT_ROUTE], permissions: [HealthDataAccess.READ_WRITE, HealthDataAccess.READ_WRITE],);
On Android, write access to WORKOUT_ROUTE also requests android.permission.health.WRITE_EXERCISE_ROUTE, so declare it in android/app/src/main/AndroidManifest.xml.
To request locationWhenInUse as well:
await Permission.location.request();await Permission.locationWhenInUse.request();// Then request the workout and route permissionsawait health.requestAuthorization( [HealthDataType.WORKOUT, HealthDataType.WORKOUT_ROUTE], permissions: [HealthDataAccess.READ_WRITE, HealthDataAccess.READ_WRITE],);
Check Health Connect, then request the health data permissions:
Future<bool> setupAndroidPermissions() async { // 1. Check Health Connect availability final status = await health.getHealthConnectSdkStatus(); if (status != HealthConnectSdkStatus.sdkAvailable) { // Installing helps only when Health Connect is missing or too old if (status == HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired) { await health.installHealthConnect(); } return false; } // 2. Request health data permissions final types = [ HealthDataType.STEPS, HealthDataType.WORKOUT, HealthDataType.DISTANCE_DELTA, // needed to read workouts HealthDataType.TOTAL_CALORIES_BURNED, // needed to read workouts HealthDataType.HEART_RATE, ]; return await health.requestAuthorization(types);}
On Android, the plugin reads the distance, total calories and steps of every workout, and returns no workouts when one of these reads is refused. To read workouts, also request READ for DISTANCE_DELTA, TOTAL_CALORIES_BURNED and STEPS, as the sample does. For how each platform computes the totals, see Workout values.
Apps can read, but not write, some iOS health data. Always request READ for these types:
final readOnlyTypes = [ HealthDataType.ELECTROCARDIOGRAM, // Apple Watch only HealthDataType.HIGH_HEART_RATE_EVENT, // Apple Watch only HealthDataType.LOW_HEART_RATE_EVENT, // Apple Watch only HealthDataType.IRREGULAR_HEART_RATE_EVENT, // Apple Watch only HealthDataType.WALKING_HEART_RATE, // Calculated by iOS HealthDataType.GENDER, // User profile data HealthDataType.BLOOD_TYPE, // User profile data HealthDataType.BIRTH_DATE, // User profile data];// Always use READ for these typesawait health.requestAuthorization( readOnlyTypes, permissions: readOnlyTypes.map((t) => HealthDataAccess.READ).toList(),);
Requesting WRITE or READ_WRITE for ELECTROCARDIOGRAM, HIGH_HEART_RATE_EVENT, LOW_HEART_RATE_EVENT, IRREGULAR_HEART_RATE_EVENT, WALKING_HEART_RATE or ATRIAL_FIBRILLATION_BURDEN throws an ArgumentError. For GENDER, BLOOD_TYPE and BIRTH_DATE, WRITE throws a PlatformException, and READ_WRITE requests READ only.
Known issue
The plugin does not check APPLE_STAND_HOUR, APPLE_STAND_TIME, APPLE_MOVE_TIME, EXERCISE_TIME or SLEEP_WRIST_TEMPERATURE, which are also read-only. When you request WRITE or READ_WRITE for one of them, HealthKit raises an exception that crashes the app. Request READ only for these types.
On Android, BMI requires weight and height data: the plugin computes BMI from them. When you request BODY_MASS_INDEX, the plugin requests WEIGHT and HEIGHT instead, with the same access level. hasPermissions() checks the same two types:
final types = [HealthDataType.BODY_MASS_INDEX];// On Android, the plugin requests WEIGHT and HEIGHT insteadawait health.requestAuthorization(types);
Request only what you need, when the user needs it:
// Request steps for main screenawait health.requestAuthorization([HealthDataType.STEPS]);// Later, when user opens workout featureawait health.requestAuthorization([HealthDataType.WORKOUT]);// When user wants to log weightawait health.requestAuthorization( [HealthDataType.WEIGHT], permissions: [HealthDataAccess.READ_WRITE],);
Send the user to the place where they can change the permission: the Health Connect settings on Android, and the Settings app on iOS. The plugin has no method that opens the Health Connect settings, so on Android the dialog only names them:
Future<void> handlePermissionDenied() async { // On Android, direct user to Health Connect settings if (Platform.isAndroid) { showDialog( context: context, builder: (context) => AlertDialog( title: Text('Permissions Required'), content: Text( 'Please grant permissions in Health Connect settings.', ), actions: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: Text('OK'), ), ], ), ); } // On iOS, direct to Settings app if (Platform.isIOS) { showDialog( context: context, builder: (context) => AlertDialog( title: Text('Permissions Required'), content: Text( 'Please enable Health permissions in Settings > Health > Data Access & Devices.', ), actions: [ TextButton( onPressed: () => openAppSettings(), child: Text('Open Settings'), ), ], ), ); }}
Check each type and request only the missing ones:
class PermissionManager { final Health health; PermissionManager(this.health); Future<Map<HealthDataType, bool?>> checkAllPermissions( List<HealthDataType> types, ) async { final results = <HealthDataType, bool?>{}; for (final type in types) { final hasPermission = await health.hasPermissions([type]); results[type] = hasPermission; } return results; } Future<void> requestMissingPermissions( List<HealthDataType> types, ) async { final missingTypes = <HealthDataType>[]; for (final type in types) { final hasPermission = await health.hasPermissions([type]); if (hasPermission != true) { missingTypes.add(type); } } if (missingTypes.isNotEmpty) { await health.requestAuthorization(missingTypes); } }}
Track READ and WRITE access per type. Pass permissions to hasPermissions() to check a specific access level:
Problem: the user denied permissions, and they cannot be requested again.
Solution: guide the user to the Settings app:
showDialog( context: context, builder: (context) => AlertDialog( title: Text('Enable Health Access'), content: Text( '1. Open Settings app\n' '2. Scroll to ${yourAppName}\n' '3. Tap Health\n' '4. Enable the data types you want to share' ), actions: [ TextButton( onPressed: () => openAppSettings(), child: Text('Open Settings'), ), ], ),);
Health Connect not available
Problem: Health Connect returns an unavailable status.
Solution: check the SDK status and act on it:
final status = await health.getHealthConnectSdkStatus();switch (status) { case HealthConnectSdkStatus.sdkUnavailable: // Cannot be used on this device: hide the health features break; case HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired: // Missing or too old (Android 9 to 13): offer to install or update await health.installHealthConnect(); break; case HealthConnectSdkStatus.sdkAvailable: // All good! break; case null: // Not on Android, or the check failed break;}
hasPermissions returns null
Problem: the permission check returns null on iOS.
Solution: this is expected behavior for privacy. Always request the permissions:
final hasPermission = await health.hasPermissions(types);// On iOS, hasPermission will be null for READif (hasPermission != true) { // Request regardless await health.requestAuthorization(types);}