You are reading the docs for Health13.x, an older version. Go to 14.x, the latest version.
Quickstart
Configure the health plugin, request permissions, and read, write and delete health data.
Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor
This guide walks through the core Health API: configuration, permissions, and reading, writing and deleting data. For a complete working app, see the example app in carp-health-flutter/example.
Import the package, create a Health instance and call configure(). Call configure() once when your app starts; it looks up the device ID that deviceId returns.
import 'package:health/health.dart';final health = Health();await health.configure();
In a StatefulWidget, configure the instance from initState():
final types = [ HealthDataType.STEPS, HealthDataType.HEART_RATE,];final granted = await health.requestAuthorization(types);if (granted) { print('✓ Authorization request completed');} else { print('✗ Authorization request failed or nothing was granted');}
On Android, true means that the user granted at least one of the requested permissions. On iOS, it means only that HealthKit processed the request, because HealthKit does not tell apps whether the user granted READ access.
To request a specific access level for each type, pass a permissions list with one entry per type:
final types = [ HealthDataType.STEPS, HealthDataType.HEART_RATE, HealthDataType.WORKOUT, HealthDataType.WEIGHT,];final permissions = [ HealthDataAccess.READ, // Steps: read only HealthDataAccess.READ, // Heart rate: read only HealthDataAccess.READ_WRITE, // Workout: read and write HealthDataAccess.READ_WRITE, // Weight: read and write];final granted = await health.requestAuthorization( types, permissions: permissions,);
On Android, the user needs Google Health Connect installed:
// Check detailed statusfinal status = await health.getHealthConnectSdkStatus();print('Health Connect status: $status');if (status == HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired) { // Open Play Store to install or update Health Connect await health.installHealthConnect();}
Health Connect is the modern replacement for Google Fit on Android. On Android 14 and later, it is part of Android. On Android 9 to 13, it is an app from Google Play, and the status is sdkUnavailableProviderUpdateRequired while that app is missing or outdated.
With sdkUnavailable, for example on Android 8, Health Connect cannot run, so hide your health features. See Health Connect for the full API.
For step totals, use the optimized getTotalStepsInInterval() method. Unlike a sum of step samples, it does not count steps twice when several sources, such as a phone and a watch, record the same steps:
final now = DateTime.now();final midnight = DateTime(now.year, now.month, now.day);final steps = await health.getTotalStepsInInterval(midnight, now);print('Steps today: ${steps ?? 0}');
On Android, the plugin saves the totals as separate distance and calorie records, so the workout also needs WRITE permission for DISTANCE_DELTA and TOTAL_CALORIES_BURNED. Without it, writeWorkoutData() returns false.
On iOS, once the user denies a permission, requestAuthorization() does not ask again: only the user can change it, in the Settings app or the Health app. Guide the user to:
Open the Settings app.
Scroll to your app.
Tap Health.
Enable the data types you need.
Health Connect not installed (Android)
Use the installation helper:
if (await health.getHealthConnectSdkStatus() == HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired) { await health.installHealthConnect();}
No data returned
Common causes:
Permissions are not granted.
No data exists for the time range.
On Android: Health Connect is not synced.
HealthKit protects its data while the device is locked, so on iOS a read on a locked device throws a PlatformException instead of returning no data. Read again once the user unlocks the device.