Install & Configure
Use this page to add the plugin dependency, initialize it, and wire permissions at a high level. Platform-specific configuration is on separate pages.
Add dependency
Terminal window flutter pub add healthpubspec.yaml dependencies:health:path: ../carp-health-flutter # or use your published package sourceIf you use a published version instead of the local path, replace with the appropriate version constraint.
Initialize the plugin
import 'package:health/health.dart';final health = Health();Future<void> bootstrap() async {// Must be called once before using any methodsawait health.configure();}The
configure()resolves a stable device identifier and registers JSON factories. You can pass a customDeviceInfoPlugintoHealth()for testing.Request permissions when needed
final types = [HealthDataType.STEPS,HealthDataType.HEART_RATE,HealthDataType.WEIGHT,];final permissions = types.map((t) => HealthDataAccess.READ_WRITE).toList();final hasPerms = await health.hasPermissions(types, permissions: permissions);if (hasPerms != true) {final ok = await health.requestAuthorization(types, permissions: permissions);if (!ok) {// Show guidance to user}}On iOS, some types only support READ. On Android, WRITE for certain ECG-related event types is not allowed. The plugin validates and throws
ArgumentErrorfor illegal combinations.Platform-specific setup
- Android: Health Connect permissions in
AndroidManifest.xml, activity recognition, optional history/background permissions, and Health Connect install flow. - iOS: Enable HealthKit capability and add
NSHealthShareUsageDescriptionandNSHealthUpdateUsageDescriptiontoInfo.plist.
- Android: Health Connect permissions in
Follow the dedicated guides: