|
|
|
|
@ -34,7 +34,7 @@ class _syncHealthDataButtonState extends State<syncHealthDataButton> {
|
|
|
|
|
|
|
|
|
|
int MedCategoryID = 0;
|
|
|
|
|
|
|
|
|
|
HealthFactory health = HealthFactory();
|
|
|
|
|
// HealthFactory health = HealthFactory();
|
|
|
|
|
List<HealthDataType> types = [HealthDataType.STEPS, HealthDataType.HEART_RATE, Platform.isAndroid ? HealthDataType.DISTANCE_DELTA : HealthDataType.DISTANCE_WALKING_RUNNING];
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -48,29 +48,29 @@ class _syncHealthDataButtonState extends State<syncHealthDataButton> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkPermissions() async {
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
if (await PermissionService.isHealthDataPermissionEnabled()) {
|
|
|
|
|
await health.requestAuthorization(types).then((value) {
|
|
|
|
|
if (value) {
|
|
|
|
|
readAll();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showPermissionConsentDialog(context, TranslationBase.of(context).physicalActivityPermission, () async {
|
|
|
|
|
await health.requestAuthorization(types).then((value) {
|
|
|
|
|
if (value) {
|
|
|
|
|
readAll();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
await health.requestAuthorization(types).then((value) {
|
|
|
|
|
if (value) {
|
|
|
|
|
readAll();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// if (Platform.isAndroid) {
|
|
|
|
|
// if (await PermissionService.isHealthDataPermissionEnabled()) {
|
|
|
|
|
// await health.requestAuthorization(types).then((value) {
|
|
|
|
|
// if (value) {
|
|
|
|
|
// readAll();
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// } else {
|
|
|
|
|
// Utils.showPermissionConsentDialog(context, TranslationBase.of(context).physicalActivityPermission, () async {
|
|
|
|
|
// await health.requestAuthorization(types).then((value) {
|
|
|
|
|
// if (value) {
|
|
|
|
|
// readAll();
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// await health.requestAuthorization(types).then((value) {
|
|
|
|
|
// if (value) {
|
|
|
|
|
// readAll();
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void readAll() async {
|
|
|
|
|
@ -83,13 +83,13 @@ class _syncHealthDataButtonState extends State<syncHealthDataButton> {
|
|
|
|
|
DateTime startDate = DateTime.now().subtract(new Duration(days: 30));
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
List<HealthDataPoint> healthData = await health.getHealthDataFromTypes(startDate, DateTime.now(), types);
|
|
|
|
|
_healthDataList.addAll(healthData);
|
|
|
|
|
// List<HealthDataPoint> healthData = await health.getHealthDataFromTypes(startDate, DateTime.now(), types);
|
|
|
|
|
// _healthDataList.addAll(healthData);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print("Caught exception in getHealthDataFromTypes: $e");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_healthDataList = HealthFactory.removeDuplicates(_healthDataList);
|
|
|
|
|
// _healthDataList = HealthFactory.removeDuplicates(_healthDataList);
|
|
|
|
|
|
|
|
|
|
_healthDataList.forEach((x) {
|
|
|
|
|
if (x.type == HealthDataType.STEPS) {
|
|
|
|
|
|