Skip to content
forked from krokyze/FitKit

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.

License

Notifications You must be signed in to change notification settings

KingLudwig94/FitKit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FitKit ()

pub package

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.

Usage

To use this plugin, add fit_kit as a dependency in your pubspec.yaml file.

Getting Started

Android

Enable Fitness API and obtain an OAuth 2.0 client ID.

iOS

Enable HealthKit and add NSHealthShareUsageDescription key to the Info.plist file.

Sample Usage

If you're using more than one FitDataType it's advised to call requestPermissions with all the data types once, otherwise iOS HealthKit will ask to approve every permission one by one in separate screens.

import 'package:fit_kit/fit_kit.dart';

void read() async {
  final results = await FitKit.read(
    FitDataType.HEART_RATE,
    dateFrom: DateTime.now().subtract(Duration(days: 5)),
    dateTo: DateTime.now(),
  );
}

void readLast() async {
  final result = await FitKit.readLast(FitDataType.HEIGHT);
}

void readAll() async {
  if (await FitKit.requestPermissions(FitDataType.values)) {
    for (FitDataType type in FitDataType.values) {
      final results = await FitKit.read(
        type,
        dateFrom: DateTime.now().subtract(Duration(days: 5)),
        dateTo: DateTime.now(),
      );
    }
  }
}

Supported data types

These are currently available data types and their corresponding GoogleFit/HealthKit types.

Data Type Android (GoogleFit) iOS (HealthKit) Unit
HEART_RATE TYPE_HEART_RATE_BPM heartRate count/min
STEP_COUNT TYPE_STEP_COUNT_DELTA stepCount count
HEIGHT TYPE_HEIGHT height meter
WEIGHT TYPE_WEIGHT bodyMass kilogram
DISTANCE TYPE_DISTANCE_DELTA distanceWalkingRunning meter
ENERGY TYPE_CALORIES_EXPENDED activeEnergyBurned kilocalorie
WATER TYPE_HYDRATION dietaryWater >= iOS 9 liter
SLEEP FitnessActivities.SLEEP sleepAnalysis iOS:
0 - inBed
1 - asleep
2 - awake
Android:
72 - SLEEP
109 - SLEEP_LIGHT
110 - SLEEP_DEEP
111 - SLEEP_REM
112 - SLEEP_AWAKE

BE AWARE

  • Calling await FitKit.read(FitDataType) without any extra parameters can lead to FAILED BINDER TRANSACTION on Android devices because of the data batch size being too large.

There's some differences on iOS for these methods:

  • FitKit.hasPermissions - false means no, true means user has approved or declined permissions.

    To help prevent possible leaks of sensitive health information, your app cannot determine whether or not a user has granted permission to read data. If you are not given permission, it simply appears as if there is no data of the requested type in the HealthKit store. https://developer.apple.com/documentation/healthkit/hkhealthstore/1614154-authorizationstatus

  • FitKit.revokePermissions - isn't supported by HealthKit, method does nothing.

About

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 50.4%
  • Dart 26.6%
  • Kotlin 19.1%
  • Ruby 3.5%
  • Objective-C 0.4%