krokyze / FitKit

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.
BSD 2-Clause "Simplified" License
98 stars 72 forks source link

FitKit () - 🚧 UNMAINTAINED 🚧

Alternative: https://pub.dev/packages/health

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 DataType 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 {
  try {
    final results = await FitKit.read(
      DataType.HEART_RATE,
      dateFrom: DateTime.now().subtract(Duration(days: 5)),
      dateTo: DateTime.now(),
    );
  } on UnsupportedException catch (e) {
    // thrown in case e.dataType is unsupported
  }
}

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

void readAll() async {
  if (await FitKit.requestPermissions(DataType.values)) {
    for (DataType type in DataType.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
STAND_TIME Not supported appleStandTime >= iOS 13 minute
EXERCISE_TIME Not supported appleExerciseTime >= iOS 9.3 minute
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

There's some differences on iOS for these methods: