|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:collection/collection.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/models/SmartWatch/HealthData.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/services/smartwatch_integration/SmartWatchIntegrationService.dart';
|
|
|
|
@ -8,6 +10,7 @@ import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
|
|
|
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
|
|
|
|
|
import 'package:fit_kit/fit_kit.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:health/health.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
|
|
|
|
|
class syncHealthDataButton extends StatefulWidget {
|
|
|
|
@ -26,6 +29,8 @@ class syncHealthDataButton extends StatefulWidget {
|
|
|
|
|
class _syncHealthDataButtonState extends State<syncHealthDataButton> {
|
|
|
|
|
List<DataType> dataTypes = List();
|
|
|
|
|
|
|
|
|
|
List<HealthDataPoint> _healthDataList = [];
|
|
|
|
|
|
|
|
|
|
List<healthData> Med_InsertTransactionsInputsList = new List();
|
|
|
|
|
List<healthData> Med_InsertTransactionsInputsList2 = new List();
|
|
|
|
|
|
|
|
|
@ -56,12 +61,53 @@ class _syncHealthDataButtonState extends State<syncHealthDataButton> {
|
|
|
|
|
padding: const EdgeInsets.all(20.0),
|
|
|
|
|
child: DefaultButton(TranslationBase.of(context).syncHealthData, () {
|
|
|
|
|
print("ReadAll");
|
|
|
|
|
readAll();
|
|
|
|
|
fetchData();
|
|
|
|
|
// readAll();
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future fetchData() async {
|
|
|
|
|
// get everything from midnight until now
|
|
|
|
|
DateTime startDate = DateTime(2021, 11, 01, 0, 0, 0);
|
|
|
|
|
DateTime endDate = DateTime(2021, 12, 06, 23, 59, 59);
|
|
|
|
|
|
|
|
|
|
HealthFactory health = HealthFactory();
|
|
|
|
|
|
|
|
|
|
// define the types to get
|
|
|
|
|
List<HealthDataType> types = [
|
|
|
|
|
HealthDataType.STEPS,
|
|
|
|
|
HealthDataType.HEART_RATE,
|
|
|
|
|
Platform.isAndroid ? HealthDataType.DISTANCE_DELTA : HealthDataType.DISTANCE_WALKING_RUNNING
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// you MUST request access to the data types before reading them
|
|
|
|
|
// bool accessWasGranted = await health.requestAuthorization(types);
|
|
|
|
|
await health.requestAuthorization(types);
|
|
|
|
|
|
|
|
|
|
int steps = 0;
|
|
|
|
|
try {
|
|
|
|
|
List<HealthDataPoint> healthData = await health.getHealthDataFromTypes(startDate, endDate, types);
|
|
|
|
|
_healthDataList.addAll(healthData);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
print("Caught exception in getHealthDataFromTypes: $e");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// filter out duplicates
|
|
|
|
|
_healthDataList = HealthFactory.removeDuplicates(_healthDataList);
|
|
|
|
|
|
|
|
|
|
// print the results
|
|
|
|
|
_healthDataList.forEach((x) {
|
|
|
|
|
if(x.type == HealthDataType.STEPS) {
|
|
|
|
|
print("Data point: $x");
|
|
|
|
|
steps += x.value.round();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
print("Steps: $steps");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void readAll() async {
|
|
|
|
|
TransactionsListID = 1;
|
|
|
|
|
var MedSubCategoryID = 0;
|
|
|
|
@ -160,7 +206,6 @@ class _syncHealthDataButtonState extends State<syncHealthDataButton> {
|
|
|
|
|
void getAllHealthDataLists() {
|
|
|
|
|
var totalSteps = 0.0;
|
|
|
|
|
var totalDistance = 0.0;
|
|
|
|
|
// double totalCalories = 0.0 ;
|
|
|
|
|
double totalHeartRate = 0.0;
|
|
|
|
|
double avgTotalHeartRate = 0.0;
|
|
|
|
|
var counter = 0;
|
|
|
|
@ -190,7 +235,6 @@ class _syncHealthDataButtonState extends State<syncHealthDataButton> {
|
|
|
|
|
value.forEach((element) {
|
|
|
|
|
if (element['MedCategoryID'] == 6) {
|
|
|
|
|
MedCategoryID = 6;
|
|
|
|
|
|
|
|
|
|
totalSteps += element['Value'];
|
|
|
|
|
} else if (element['MedCategoryID'] == 7) {
|
|
|
|
|
MedCategoryID = 7;
|
|
|
|
@ -209,10 +253,6 @@ class _syncHealthDataButtonState extends State<syncHealthDataButton> {
|
|
|
|
|
Med_InsertTransactionsInputsList2.add(new healthData(
|
|
|
|
|
MedCategoryID: 4, MedSubCategoryID: element['MedSubCategoryID'], MachineDate: DateUtil.convertDateToString(date), Value: element['Value'], TransactionsListID: TransactionsListID++));
|
|
|
|
|
}
|
|
|
|
|
// else if(element['MedCategoryID'] == 8){
|
|
|
|
|
//
|
|
|
|
|
// totalCalories += element['Value'] ;
|
|
|
|
|
// }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (counter == 0) {
|
|
|
|
|