Giter Site home page Giter Site logo

paulkastel / fitkit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from krokyze/fitkit

0.0 1.0 0.0 127 KB

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

License: BSD 2-Clause "Simplified" License

Kotlin 36.86% Ruby 8.70% Swift 29.48% Objective-C 0.83% Dart 24.13%

fitkit's Introduction

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 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

  • Calling await FitKit.read(dataType) 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.