GithubHelp home page GithubHelp logo

trygil / fitness Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dev-juyoung/fitness

0.0 0.0 0.0 216 KB

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

License: MIT License

Kotlin 36.63% Ruby 5.47% Swift 28.18% Objective-C 1.62% Dart 28.10%

fitness's Introduction

Fitness

pub package

Flutter plugin for reading step count data. Wraps HealthKit on iOS and GoogleFit on Android.

Related Document

๐Ÿ‘‰ Korean

Getting Started

Check out the example directory for a sample app.

Add pubspec.yaml

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

Android Integration

Enable Fitness API and obtain an OAuth 2.0 client ID.

iOS Integration

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

Usage

Fitness.hasPermission

Check if the user has previously granted the necessary data access.

Note: Quite rightly so, Apple deems even the information as to whether a user accepted or denied the read permission for HealthKit as sensitive information. For this reason, HealthKit does not have a clear way to check permissions.

As a workaround, it checks whether you can read data within the last month or not to see if you actually have read access.

void _hasPermission() async {
  final result = await Fitness.hasPermission();
}

Fitness.requestPermission

Initiate the authorization flow.

  • Android: Request OAuth permission and request permission to read step count history from Google Fit. It also creates a subscription to synchronize step count data.

  • iOS: Request permission to read step count history from Health Kit. Since it returns whether the request for HKHealthStore.requestAuthorization was successful or not, it is recommended to use Fitness.hasPermission in the case of iOS to check if there is permission again.

void _requestPermission() async {
  final result = await Fitness.requestPermission();
}

Fitness.revokePermission

  • Android: All OAuth permissions granted to Googlt Fit are revoked and all subscriptions created in the app are removed.

  • iOS: Feature is not supported, so it always returns true.

void _revokePermission() async {
  final result = await Fitness.revokePermission();
}

Fitness.read

Requests user's step data with Google Fit or Health Kit.

When requested without any arguments, the daily step count is requested by default.

Parameters
  • timeRange
    • defaults: from 00:00:00 to 23:59:59
    • type: TimeRange [class]
  • bucketByTime
    • defaults: 1
    • type: int
  • timeUnit
    • defaults: TimeUnit.day
    • type: TimeUnit [enum]
// Request data for the last 7 days.
void _read() async {
  final now = DateTime.now();
  final results = await Fitness.read(
    timeRange: TimeRange(
      start: now.subtract(const Duration(days: 7)),
      end: now,
    ),
    bucketByTime: 1,
    timeUnit: TimeUnit.days,
  );
}

fitness's People

Contributors

dev-juyoung avatar trygil avatar

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.