fitness
걸음 수 데이터를 읽기 위한 Flutter 플러그인입니다. iOS에서는 HealthKit을, Android에서는 GoogleFit을 래핑합니다.
건강 및 피트니스 데이터를 읽기 위한 플러터 플러그인입니다. iOS에서는 HealthKit을, Android에서는 GoogleFit을 래핑합니다.
{"sdk":"flutter"}{"sdk":"flutter"}아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Flutter plugin for reading step count data. Wraps HealthKit on iOS and GoogleFit on Android.
:point_right: Korean
Check out the example directory for a sample app.
To use this plugin, add fitness as a dependency in your pubspec.yaml file.
Enable Fitness API and obtain an OAuth 2.0 client ID.
Enable HealthKit and add NSHealthShareUsageDescription key to the Info.plist file.
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();
}
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();
}
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();
}
Requests user's step data with Google Fit or Health Kit.
When requested without any arguments, the daily step count is requested by default.
TimeRange [class]intTimeUnit [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,
);
}