我在我的颤振应用程序中使用了 health-3.0.3 来获取 Google fit 数据。我能够获得除 STEP 数据以外的所有数据,它总是显示为零。
你可以参考这里的健康包 Health 3.0.3 Flutter
这是在我的应用程序中访问 STEP 数据类型的代码块
List<HealthDataType> types = [
HealthDataType.STEPS,
HealthDataType.WEIGHT,
//HealthDataType.HEIGHT,
];
setState(() => _state = AppState.FETCHING_DATA);
/// You MUST request access to the data types before reading them
bool accessWasGranted = await health.requestAuthorization(types);
double steps = 0;
if (accessWasGranted) {
try {
/// Fetch new data
List<HealthDataPoint> healthData =
await health.getHealthDataFromTypes(startDate, endDate, types);
/// Save all the new data points
_healthDataList.addAll(healthData);
} catch (e) {
print("Caught exception in getHealthDataFromTypes: $e");
}
/// Filter out duplicates
_healthDataList = HealthFactory.removeDuplicates(_healthDataList);
/// Print the results
_healthDataList.forEach((x) {
print("Data point: $x");
steps += (x.value as double);
});
print("Steps: $steps");
您可以参考给定链接中示例选项卡下的完整代码。有谁知道这里有什么问题?