Skip to content
CARP Docs
Ask AISystemLightDark
On this page

You are reading the docs for Health 13.x, an older version. Go to 14.x, the latest version.

Installation

Add the health plugin to a Flutter app, configure it, and request permissions.

Copy MarkdownOpen inOpen in GitHubView as MarkdownOpen in Scira AIOpen in ChatGPTOpen in ClaudeOpen in Cursor

This page covers the dependency, initialization and permission requests. Platform-specific configuration is described in Android setup and iOS setup.

  1. Add the dependency

    pub.devLocal path
    flutter pub add "health:^13.3.2"
    pubspec.yaml
    # pubspec.yaml
    dependencies:
      health:
        path: ../carp-health-flutter  # or use your published package source

    If you use a published version instead of the local path, replace the path with the appropriate version constraint.

  2. Initialize the plugin

    Call configure() once, before you use any other method:

    import 'package:health/health.dart';
    
    final health = Health();
    
    Future<void> bootstrap() async {
      // Must be called once before using any methods
      await health.configure();
    }

    configure() looks up the ID that deviceId returns. On Android, this is Build.ID, a build label that all devices with the same Android build share; on iOS, it is the identifierForVendor. For testing, you can pass a custom DeviceInfoPlugin to Health().

  3. Request permissions when needed

    Check which permissions are granted and request the missing ones:

    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
      }
    }

    requestAuthorization() throws an ArgumentError when:

    • permissions and types differ in length;
    • permissions asks 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_RATE or ATRIAL_FIBRILLATION_BURDEN.

    See Permissions for the full permission model.

  4. Configure each platform

    • Android: set minSdk to 26 or later, make MainActivity extend FlutterFragmentActivity, declare the Health Connect permissions, queries and privacy policy entries in AndroidManifest.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 NSHealthShareUsageDescription and NSHealthUpdateUsageDescription to Info.plist.

Next steps

Android setup

Health Connect permissions, runtime permissions, and history and background access.

iOS setup

HealthKit capability and Info.plist usage descriptions.

Quickstart

Read, write and delete health data.

Quick links

Page · DocumentationCARP DocumentationPage · DocumentationIntroductionPage · DocumentationQuickstartPage · DocumentationTerminologyPage · DocumentationArchitecture