nano_healthkit_plugin 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new44

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 #

Permissions #

Request permissions to read heart rate and height:

var request = HealthTypeList();
request.types.add(HealthTypes.QUANTITY_HEART_RATE);
request.types.add(HealthTypes.QUANTITY_HEIGHT);
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:

{
  type: QUANTITY_HEART_RATE
  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
    bundleIdentifier: com.apple.Health
  }
  quantityData: {
    count: 1
    quantityUnit: count/s
    quantity: 2.1666666666666665
  }
}

Subscribe #

Subscribe to new entries of height:

var request = HealthTypeList();
request.types.add(HealthTypes.QUANTITY_HEIGHT);
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.

1.0.0 #

  • Initial release.

example/README.md

Nano's Healthkit Plugin Example for Flutter #

Installation #

Remeber cd to the folder example/ios and run pod install.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  nano_healthkit_plugin: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:nano_healthkit_plugin/nano_healthkit_plugin.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/nano_healthkit_plugin.dart. (-1 points)

Analysis of lib/nano_healthkit_plugin.dart reported 2 hints:

line 3 col 8: Unused import: 'dart:ui'.

line 6 col 8: Unused import: 'package:flutter/widgets.dart'.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Format lib/healthdata.pb.dart.

Run flutter format to format lib/healthdata.pb.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/healthdata.pbenum.dart (Run flutter format to format lib/healthdata.pbenum.dart.)
  • lib/healthdata.pbjson.dart (Run flutter format to format lib/healthdata.pbjson.dart.)
  • lib/healthdata.pbserver.dart (Run flutter format to format lib/healthdata.pbserver.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (protobuf).

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
convert ^2.1.1 2.1.1
flutter 0.0.0
protobuf 0.13.15 0.13.15 1.0.1
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
fixnum 0.10.11
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test