搜尋套件、儲存庫與 APP 分類

套件詳情v1.0.1

fitness

用於讀取步數資料的 Flutter 插件。在 iOS 上封裝 HealthKit,在 Android 上封裝 GoogleFit。

AndroidiOS
近 30 天下載
50
喜歡數
29
Pub 分數
140

安裝套件

flutter pub add fitness

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

健身套件是一個Flutter外掛程式,可從原生健康平台存取步數資料。在iOS上,它整合HealthKit;在Android上,則連接到Google Fit。這讓開發者能以跨平台方式取得步數資訊,簡化健康資料整合至健身或健康應用程式的過程。此外掛程式會自動處理平台特定的設定與權限,提供跨裝置的一致API。

適用情境

  • 追蹤每日步數
  • 建構健身儀表板
  • 與健康分析整合
  • 啟用使用者活動目標
  • 支援健康應用

主要特色

  • 跨平台步數訪問
  • HealthKit (iOS) 結合
  • Google Fit(Android)整合
  • 自動權限處理
  • 用於取得步數資料的簡單API

適合對象

  • 健身應用開發者
  • 健康應用程式創作者
  • 健康數據整合商
  • 面向 iOS 和 Android 的移動開發者

使用建議

  • 需要在兩個平台上取得使用者權限
  • 需要在 iOS 和 Android 清單中進行正確設定
  • 僅限步數(不包括其他健康指標)
  • 取決於使用者是否啟用健康Kit或Google Fit
  • 可能需要設定背景執行以實現持續追蹤

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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,
  );
}

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。