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 initializes the plugin for the current platform.
import 'package:health/health.dart';final health = Health();await health.configure();
In a StatefulWidget, configure the instance from initState():
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,);
Android runtime permissions
On Android, if you use STEPS or workout data, you also need to request the activity recognition and location runtime permissions. Use the permission_handler package. See Android runtime permissions.
On Android, the user needs Google Health Connect installed:
// Check if Health Connect is availablefinal available = await health.isHealthConnectAvailable();if (!available) { // Open Play Store to install Health Connect await health.installHealthConnect();}// Check detailed statusfinal status = await health.getHealthConnectSdkStatus();print('Health Connect status: $status');
Health Connect is the modern replacement for Google Fit on Android. Most devices running Android 14+ have it pre-installed. See Health Connect for the full API.