nano_healthkit_plugin 1.0.0
nano_healthkit_plugin: ^1.0.0 copied to clipboard

Nano Healthkit Plugin for Flutter

Nano's HealthKit Plugin for Flutter #

Flutter plugin to read data from Apple's HealthKit, request for permissions, subscribe to updates in background and run statistics queries. It also supports Health Records, batch fetching of historical data and more.

It supports readings of ALL types of data available up to iOS 13.0 (except for series types and activity summary). Check the HealthTypes section for a full list.

Currently, writing data into HealthKit is not supported.

Quick setup #

  1. Add the plugin to your project's pubspec.yaml.

  2. Enable HealthKit capabilities (and also "Clinical Health Records" and "Background fetch" if desired) in Xcode.

  3. Add the necessary entitlements in Info.plist.

Detailed instructions can be found on our wiki.

Examples #


Request permissions to read heart rate and height:

var request = HealthTypeList();
bool isAuthorized = await NanoHealthkitPlugin.authorize(request);

Read data

Fetch the latest entry of heart rate:

var request = HealthDataRequest();
request.type = HealthTypes.QUANTITY_HEART_RATE;
request.limit = 1; // If the limit is removed, it will fetch all historical data for heart rate
var response = await NanoHealthkitPlugin.fetchData(request);

The response looks like this:

  objectType: HKQuantityTypeIdentifierHeartRate
  startDate: 2019-10-03T18:30:00.000Z
  endDate: 2019-10-03T18:30:00.000Z
  metadata: {"HKWasUserEntered":1}
  uuid: FA64A6C0-B330-48D7-A6D5-B588533E9D4D
  source: {
    version: 13.0
    operatingSystemVersion: 13.0.0
    productType: iPhone12,5
    name: Health
  quantityData: {
    count: 1
    quantityUnit: count/s
    quantity: 2.1666666666666665


Subscribe to new entries of height:

var request = HealthTypeList();
NanoHealthkitPlugin.subscribeToUpdates(request, _updatesReceived);

The updatesReceived method gets all new entries (even while the app is in background) in the same structure as the fetching of data.

To enable background updates even when the app is killed, check the notes regarding this topic to know how to configure it.

Docs #

Check our Wiki for more details.