A Flutter wrapper for HealthKitReporter

  • iOS only usage, since AppleHealth is not available on Android devices.

  • The library supports reading, writing, observing values from HealthKit repository.

  • All methods from HealthKitReporter original library are wrapped in Method and Event channels provided by FlutterPlugin

Getting Started

  • Go inside pubspec.yaml file
  • Add this to your package's pubspec.yaml file:
     health_kit_reporter: ^2.1.1
  • Get dependencies
flutter pub get

How to use


At first in your app's entitlements select HealthKit and in your app's info.plist file add permissions:


If you plan to use WorkoutRoute Series please provide additionally CoreLocation permissions:


Common usage

You simply call a HealthKitReporter methods surrounding by try catch blocks.

Warning: If Apple Health is not supported by the device (i.e. iPad) the error result will occur.

The reporter supports following operations with HealthKit:

  • accessing to permissions
  • reading data
  • writing data
  • observing data changes

If you want to read, write data or observe data changes, you always need to be sure that the data types are authorized to be read/written/observed. In that case call authorization method and await for the result telling about the presentation of the authorization window. Notice that Apple Health Kit will show this window only once during the whole time app is installed on the device, in this case if some types were denied to be read or written, user should manually allow this in Apple Health App.

Requesting permissions

As was mentioned above, you need to provide HealthKit entitlements and extend the info.plist file of your App with HealthKit permissions. (see Preparation)

Call the method: requestAuthorization

For this method you need to specify the strings identifiers of types you want to get access.

In the example, we want to read data for all QuantityTypes and write data for QuantityType.stepCount:

Future<void> requestAuthorization() async {
  try {
    final readTypes = => e.identifier).toList();
    final writeTypes = <String>[
    final isRequested =
        await HealthKitReporter.requestAuthorization(readTypes, writeTypes);
    if (isRequested) {
      // read data/write data/observe data
  } catch (e) {

Warning: Please keep in mind, Apple Health Kit does not let anyone to know if reading permissions were provided.

User can decline some of the reading permissions, but the result of the function will still be true. See Authorization status

Reading Data

After authorization, you can try to start reading data.

Future<void> read(bool isRequested) async {
  if (isRequested) {
    final preferredUnits =
        await HealthKitReporter.preferredUnits([QuantityType.stepCount]);
    for (final preferredUnit in preferredUnits) {
      print('preferredUnit: ${preferredUnit.identifier}');
      final type = QuantityTypeFactory.from(preferredUnit.identifier);
      final quantities = await HealthKitReporter.quantityQuery(
      print('quantity: ${ =>}');
      final statistics = await HealthKitReporter.statisticsQuery(
      print('statistics: ${}');
    final characteristics = await HealthKitReporter.characteristicsQuery();
    print('characteristics: ${}');
    final categories = await HealthKitReporter.categoryQuery(
    print('categories: ${ =>}');
    final samples = await HealthKitReporter.sampleQuery(
    print('samples: ${ =>}');
    final sources = await HealthKitReporter.sourceQuery(
    print('sources: ${ =>}');
    final correlations = await HealthKitReporter.correlationQuery(
    print('correlations: ${ =>}');
  } else {
    print('error isRequested: $isRequested');

In the example above, there is a call of preferredUnits function. You can provide identifiers to get preferred units for them and eventually receive properly calculated values from queries. The units will be chosen automatically based on you current localization. This is only required for QuantityTypes. If you will try to provide invalid unit for a type, you will get an error.

The usage of sampleQuery for quantity types will return nearly the same result as quantityQuery, but the units for the values will be used according to SI, while quantityQuery together with preferredUnits will handle values units according to thee current localization.

Writing Data

Before writing data, you may need to check if writing is allowed by calling isAuthorizedToWrite.

If it is ok to write, you need to create a Sample object and call a save method.

final _device = Device(
final _source = Source(
final _operatingSystem = OperatingSystem(

SourceRevision get _sourceRevision => SourceRevision(

void saveSteps() async {
  try {
    final canWrite = await HealthKitReporter.isAuthorizedToWrite(
    if (canWrite) {
      final now =;
      final minuteAgo = now.add(Duration(minutes: -1));
      final harmonized = QuantityHarmonized(100, 'count', null);
      final steps = Quantity(
      print('try to save: ${}');
      final saved = await;
      print('stepsSaved: $saved');
    } else {
      print('error canWrite steps: $canWrite');
  } catch (e) {

Recommendation: As well as for reading, here will better as well to call preferredUnits first, to know what unit is valid for a type. Please see HKUnit.init

Warning: PLease be sure to provide valid values for the appropriate types. For example, HealthKit will not allow to save Quantity value for the QuantityType.stepCount if the value is 0

Observing Data

If you want to know, that something was changed in HealthKit, you can observe the repository.

Try simple observerQuery to get notifications if something is changed.

This call is a subscription for EventChannel of the plugin, so don't forget to cancel it as soon as you don't need it anymore.

 Future<void> observerQuery() async {
  final identifier = QuantityType.stepCount.identifier;
  final sub = HealthKitReporter.observerQuery(
    onUpdate: (identifier) async {
      print('Updates for observerQuerySub');
  print('observerQuerySub: $sub');
  final isSet = await HealthKitReporter.enableBackgroundDelivery(
  print('enableBackgroundDelivery: $isSet');

According to Observing Query and Background Delivery you might create an App which will be called every time by HealthKit, even if the app is in background, to notify, that some data was changed in HealthKit depending on frequency. But keep in mind that sometimes the desired frequency you set cannot be fulfilled by HealthKit.

To receive notifications when the app is killed by the system or in background:

  • provide an additional capability Background Mode and select Background fetch
  • with calling observerQuery, you need to call enableBackgroundDelivery function as well

As a recommendation set up the subscription inside initState or build methods of your widget or as more preferred in main function of your app.

If you want to stop observation, you need to:

  • remove the subscription for observerQuery
  • call disableBackgroundDelivery or disableAllBackgroundDelivery


The library supports minimum iOS 9. Some features like HeartbeatSeries are available only starting with iOS 13.0 and like Electrocardiogramm starting with iOS 14.0.


Under MIT License


If you think that my repo helped you to solve the issues you struggle with, please don't be shy and sponsor :-)