1.1.22+3 corrections
This commit is contained in:
@@ -7,6 +7,8 @@ import 'package:aitrainer_app/model/customer_training_plan_details.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/training_plan.dart';
|
||||
import 'package:aitrainer_app/model/training_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/training_plan_repository.dart';
|
||||
import 'package:aitrainer_app/service/exercise_service.dart';
|
||||
@@ -29,6 +31,9 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
CustomerTrainingPlan? _myPlan;
|
||||
CustomerTrainingPlanDetails? _myDetail;
|
||||
|
||||
TrainingPlan? _myTrainingPlan;
|
||||
final List<String> trainingPlanDayNames = [];
|
||||
|
||||
bool started = false;
|
||||
final List<String> dayNames = [];
|
||||
bool restarting = false;
|
||||
@@ -38,6 +43,9 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
CustomerTrainingPlan? getMyPlan() => this._myPlan;
|
||||
setMyPlan(CustomerTrainingPlan? myPlan) => this._myPlan = myPlan;
|
||||
|
||||
TrainingPlan? getMyTrainingPlan() => this._myTrainingPlan;
|
||||
setMyTrainingPlan(TrainingPlan? myTrainingPlan) => this._myTrainingPlan = myTrainingPlan;
|
||||
|
||||
CustomerTrainingPlanDetails? getMyDetail() => this._myDetail;
|
||||
setMyDetail(CustomerTrainingPlanDetails? value) => this._myDetail = value;
|
||||
|
||||
@@ -88,6 +96,10 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
yield TrainingPlanReady();
|
||||
} else if (event is TrainingPlanSaveExercise) {
|
||||
yield TrainingPlanLoading();
|
||||
if (event.detail.repeats == -1) {
|
||||
yield TrainingPlanReady();
|
||||
throw Exception("Please type your repeats!");
|
||||
}
|
||||
if (event.detail.weight == -3) {
|
||||
print("DropSet");
|
||||
event.detail.state = ExercisePlanDetailState.finished;
|
||||
@@ -293,6 +305,83 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
getActiveDayIndex();
|
||||
}
|
||||
|
||||
void activateTrainingPlanDays() {
|
||||
if (_myTrainingPlan == null || _myTrainingPlan!.details == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
trainingPlanDayNames.clear();
|
||||
|
||||
String dayName = ".";
|
||||
_myTrainingPlan!.details!.forEach((element) {
|
||||
if (element.day != null && element.day != dayName) {
|
||||
trainingPlanDayNames.add(element.day!);
|
||||
dayName = element.day!;
|
||||
}
|
||||
});
|
||||
|
||||
if (trainingPlanDayNames.length == 0) {
|
||||
dayName = "";
|
||||
trainingPlanDayNames.add(dayName);
|
||||
}
|
||||
}
|
||||
|
||||
List<TrainingPlanDetail> trainingPlanDetailSummary(TrainingPlan plan, String dayName) {
|
||||
List<TrainingPlanDetail> details = [];
|
||||
TrainingPlanDetail? prev;
|
||||
plan.details!.forEach((element) {
|
||||
if (prev == null || element.exerciseTypeId != prev!.exerciseTypeId) {
|
||||
if (element.day! == dayName) {
|
||||
element.summary = getSummary(element);
|
||||
details.add(element);
|
||||
}
|
||||
prev = element;
|
||||
}
|
||||
});
|
||||
return details;
|
||||
}
|
||||
|
||||
List<TrainingPlanDetail> getAllTrainingPlanDetailsSameExercise(TrainingPlanDetail detail) {
|
||||
List<TrainingPlanDetail> list = [];
|
||||
getMyTrainingPlan()!.details!.forEach((element) {
|
||||
if (detail.exerciseTypeId == element.exerciseTypeId) {
|
||||
list.add(element);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
String getSummary(TrainingPlanDetail detail) {
|
||||
String summary = "";
|
||||
String set = "1";
|
||||
|
||||
set = detail.set.toString() + "/ ";
|
||||
List<TrainingPlanDetail> details = getAllTrainingPlanDetailsSameExercise(detail);
|
||||
int index = 0;
|
||||
|
||||
String quantities = "";
|
||||
|
||||
details.forEach((element) {
|
||||
String delimiter = ", ";
|
||||
if (index == 0) {
|
||||
delimiter = "";
|
||||
}
|
||||
if (element.repeats == -1) {
|
||||
quantities += delimiter + " MAX ";
|
||||
} else {
|
||||
quantities += delimiter + "${element.repeats}";
|
||||
}
|
||||
|
||||
index++;
|
||||
});
|
||||
|
||||
//quantities += " / ? kg";
|
||||
|
||||
summary = quantities;
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
void addExtraExerciseType(String name, String dayName) {
|
||||
if (Cache().getExerciseTypes() == null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user