搜索插件、代码仓与 APP 分类

GitHub 代码仓dev-juyoung/Fitness

健身

用于读取健康和健身数据的 Flutter 插件。在 iOS 上封装 HealthKit,在 Android 上封装 GoogleFit。

健身 项目封面
星标
19
复刻
10
最近推送(UTC)
2022年8月2日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

Fitness

pub package

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

Related Document

:point_right: 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,
  );
}
Juyoung, Lee GitHub avatar
GitHub 作者

Juyoung, Lee ↗

In South Korea. Android Developer.

Seoul, Korea
语言KotlinSwiftDartRubyObjective-C

此仓库发布的插件

使用的依赖

依赖清单 2 项

  • flutter{"sdk":"flutter"}
  • flutter_test开发依赖{"sdk":"flutter"}

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗