WT1.1.3 logo change, error fixes
This commit is contained in:
@@ -5,21 +5,24 @@ import 'package:aitrainer_app/model/result.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_result_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
import 'package:aitrainer_app/util/trans.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
import 'package:health/health.dart';
|
||||
//import 'package:health/health.dart';
|
||||
|
||||
part 'result_event.dart';
|
||||
part 'result_state.dart';
|
||||
|
||||
class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
final ExerciseResultRepository resultRepository;
|
||||
final ExerciseRepository exerciseRepository;
|
||||
List<HealthDataPoint> _healthDataList = List();
|
||||
final BuildContext context;
|
||||
//List<HealthDataPoint> _healthDataList = List();
|
||||
DateTime startTime;
|
||||
DateTime endTime;
|
||||
final HealthFactory health = HealthFactory();
|
||||
/* final HealthFactory health = HealthFactory();
|
||||
final List<HealthDataType> types = [
|
||||
HealthDataType.ACTIVE_ENERGY_BURNED,
|
||||
HealthDataType.WATER,
|
||||
@@ -30,9 +33,9 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
HealthDataType.HIGH_HEART_RATE_EVENT,
|
||||
HealthDataType.LOW_HEART_RATE_EVENT,
|
||||
HealthDataType.RESTING_HEART_RATE
|
||||
];
|
||||
]; */
|
||||
|
||||
ResultBloc({this.resultRepository, this.exerciseRepository}) : super(ResultInitial()) {
|
||||
ResultBloc({this.resultRepository, this.exerciseRepository, this.context}) : super(ResultInitial()) {
|
||||
this.startTime = exerciseRepository.start;
|
||||
this.endTime = exerciseRepository.end;
|
||||
}
|
||||
@@ -45,7 +48,7 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
if (event is ResultLoad) {
|
||||
yield ResultLoading();
|
||||
|
||||
await _fetchHealthData();
|
||||
//await _fetchHealthData();
|
||||
_matchExerciseData();
|
||||
await resultRepository.saveExerciseResults();
|
||||
yield ResultReady();
|
||||
@@ -62,16 +65,16 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
element.exerciseId = exerciseRepository.actualExerciseList[0].exerciseId;
|
||||
switch (element.item) {
|
||||
case ResultItem.bpm_avg:
|
||||
element.data = _gethHealthDataPointValueAvg(HealthDataType.HEART_RATE);
|
||||
//element.data = _gethHealthDataPointValueAvg(HealthDataType.HEART_RATE);
|
||||
break;
|
||||
case ResultItem.bpm_min:
|
||||
element.data = element.data = _gethHealthDataPointValueMin(HealthDataType.HEART_RATE);
|
||||
//element.data = element.data = _gethHealthDataPointValueMin(HealthDataType.HEART_RATE);
|
||||
break;
|
||||
case ResultItem.bpm_max:
|
||||
element.data = element.data = _gethHealthDataPointValueMax(HealthDataType.HEART_RATE);
|
||||
//element.data = element.data = _gethHealthDataPointValueMax(HealthDataType.HEART_RATE);
|
||||
break;
|
||||
case ResultItem.calorie:
|
||||
element.data = _gethHealthDataPointValueSum(HealthDataType.ACTIVE_ENERGY_BURNED);
|
||||
//element.data = _gethHealthDataPointValueSum(HealthDataType.ACTIVE_ENERGY_BURNED);
|
||||
break;
|
||||
case ResultItem.development_percent_bodypart:
|
||||
// TODO: Handle this case.
|
||||
@@ -82,7 +85,7 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
}
|
||||
break;
|
||||
case ResultItem.fatburn_percent:
|
||||
DateTime today = DateTime.now();
|
||||
/* DateTime today = DateTime.now();
|
||||
int age = today.year - Cache().userLoggedIn.birthYear;
|
||||
double minBpm = (200 - age) * 0.6;
|
||||
double maxBpm = (200 - age) * 0.7;
|
||||
@@ -100,7 +103,7 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
element.data = (burnCounter / counter * 100);
|
||||
} else {
|
||||
element.data = 0;
|
||||
}
|
||||
} */
|
||||
break;
|
||||
case ResultItem.speed_max:
|
||||
// TODO: Handle this case.
|
||||
@@ -108,14 +111,14 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
case ResultItem.reps_volume:
|
||||
if (exerciseRepository.exerciseType.unit == "repeat") {
|
||||
double value = 0;
|
||||
exerciseRepository.actualExerciseList.forEach((element) {
|
||||
value += element.quantity;
|
||||
exerciseRepository.actualExerciseList.forEach((actual) {
|
||||
value += actual.quantity;
|
||||
});
|
||||
element.data = value;
|
||||
}
|
||||
break;
|
||||
case ResultItem.steps:
|
||||
element.data = _gethHealthDataPointValueSum(HealthDataType.STEPS);
|
||||
element.data = 0; //_gethHealthDataPointValueSum(HealthDataType.STEPS);
|
||||
break;
|
||||
/* case ResultItem.time:
|
||||
final Duration duration = this.endTime.difference(this.startTime);
|
||||
@@ -124,8 +127,8 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
case ResultItem.weight_volume:
|
||||
if (exerciseRepository.exerciseType.unitQuantityUnit == "kilogram") {
|
||||
double value = 0;
|
||||
exerciseRepository.actualExerciseList.forEach((element) {
|
||||
value += element.quantity * element.unitQuantity;
|
||||
exerciseRepository.actualExerciseList.forEach((actual) {
|
||||
value += actual.quantity * actual.unitQuantity;
|
||||
});
|
||||
element.data = value;
|
||||
}
|
||||
@@ -134,15 +137,31 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
});
|
||||
}
|
||||
|
||||
String _printDuration(Duration duration) {
|
||||
String printDuration(Duration duration, {isText = false, isDecimal = false}) {
|
||||
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
||||
String twoDigitMinutes = twoDigits(duration.inMinutes);
|
||||
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
|
||||
String twoDigitMilliSeconds = duration.inMilliseconds.remainder(1000).toString();
|
||||
return "$twoDigitMinutes:$twoDigitSeconds:$twoDigitMilliSeconds" + '"';
|
||||
if (isText) {
|
||||
if (isDecimal) {
|
||||
return "$twoDigitMinutes" + t("min") + "$twoDigitSeconds" + t("sec") + ":$twoDigitMilliSeconds" + '"';
|
||||
} else {
|
||||
return "$twoDigitMinutes" + t("min") + "$twoDigitSeconds" + t("sec");
|
||||
}
|
||||
} else {
|
||||
return "$twoDigitMinutes:$twoDigitSeconds:$twoDigitMilliSeconds" + '"';
|
||||
}
|
||||
}
|
||||
|
||||
double _gethHealthDataPointValueAvg(HealthDataType dataType) {
|
||||
String printTime(double duration) {
|
||||
String twoDigits(int n) => n.toString().padLeft(1, "0");
|
||||
String twoDigitMinutes = twoDigits((duration ~/ 60).toInt());
|
||||
String twoDigitSeconds = (duration % 60).toStringAsFixed(0);
|
||||
|
||||
return "$twoDigitMinutes " + t("minutes") + " $twoDigitSeconds";
|
||||
}
|
||||
|
||||
/* double _gethHealthDataPointValueAvg(HealthDataType dataType) {
|
||||
double value = 0;
|
||||
double counter = 0;
|
||||
_healthDataList.forEach((dataPoint) {
|
||||
@@ -193,9 +212,9 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
min = 0;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
} */
|
||||
|
||||
Future<void> _fetchHealthData() async {
|
||||
/* Future<void> _fetchHealthData() async {
|
||||
if (health == null) {
|
||||
return;
|
||||
}
|
||||
@@ -209,7 +228,7 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging {
|
||||
log("Caught exception in getHealthDataFromTypes: $e");
|
||||
throw Exception(e);
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
double calculate1RM({double percent}) {
|
||||
if (exerciseRepository.exercise == null) {
|
||||
|
||||
Reference in New Issue
Block a user