wt1.1.2 new treeview, bar chart for muscle development
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_tree.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -15,11 +13,10 @@ part 'exercise_plan_state.dart';
|
||||
|
||||
class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
final WorkoutTreeRepository menuTreeRepository;
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
int customerId;
|
||||
|
||||
ExercisePlanBloc({this.exerciseRepository, this.menuTreeRepository}) : super(ExercisePlanInitial());
|
||||
ExercisePlanBloc({this.menuTreeRepository}) : super(ExercisePlanInitial());
|
||||
|
||||
Future<void> getData() async {
|
||||
exercisePlanRepository.setCustomerId(customerId);
|
||||
@@ -29,12 +26,11 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
menuTreeRepository.sortByMuscleType();
|
||||
|
||||
menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutTree> listWorkoutTree = value;
|
||||
List<WorkoutMenuTree> listWorkoutTree = value;
|
||||
listWorkoutTree.forEach((workoutTree) {
|
||||
workoutTree.selected = false;
|
||||
if (exercisePlanRepository.exercisePlanDetails.length > 0) {
|
||||
if (exercisePlanRepository.exercisePlanDetails[workoutTree.exerciseTypeId] != null) {
|
||||
//print("bingo");
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() > 0) {
|
||||
if (exercisePlanRepository.getExercisePlanDetailByExerciseId(workoutTree.exerciseTypeId) != null) {
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
}
|
||||
@@ -42,6 +38,8 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
});
|
||||
}
|
||||
|
||||
void setExercisePlanRepository(ExercisePlanRepository repo ) => exercisePlanRepository = repo;
|
||||
|
||||
@override
|
||||
Stream<ExercisePlanState> mapEventToState(ExercisePlanEvent event) async* {
|
||||
try {
|
||||
@@ -50,38 +48,62 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
await this.getData();
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
if (event is ExercisePlanUpdate) {
|
||||
|
||||
if (event is ExercisePlanUpdateUI) {
|
||||
yield ExercisePlanLoading();
|
||||
WorkoutTree workoutTree = event.workoutTree;
|
||||
|
||||
WorkoutMenuTree workoutTree = event.workoutTree;
|
||||
if (workoutTree != null) {
|
||||
exercisePlanRepository.addExerciseTypeToPlan(workoutTree.exerciseType);
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
|
||||
yield ExercisePlanReady();
|
||||
} else if (event is ExercisePlanRemoveExercise) {
|
||||
}
|
||||
|
||||
else if (event is ExercisePlanAddExercise) {
|
||||
yield ExercisePlanLoading();
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.removeExerciseTypeFromPlan(planDetail.exerciseType);
|
||||
exercisePlanRepository.actualPlanDetail = planDetail;
|
||||
|
||||
/*if ( exercisePlanRepository.exercisePlanDetails[planDetail.exerciseTypeId] == null ) {
|
||||
print("Add plan detail " + planDetail.toJson().toString());
|
||||
exercisePlanRepository.actualPlanDetail.change = ExercisePlanDetailChange.add;
|
||||
} else {
|
||||
print("Update plan detail " + planDetail.toJson().toString());
|
||||
exercisePlanRepository.actualPlanDetail.change = ExercisePlanDetailChange.update;
|
||||
}
|
||||
exercisePlanRepository.addDetailToPlan();*/
|
||||
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
|
||||
await exercisePlanRepository.saveExercisePlan();
|
||||
}
|
||||
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
|
||||
else if (event is ExercisePlanRemoveExercise) {
|
||||
yield ExercisePlanLoading();
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(planDetail.exerciseTypeId);
|
||||
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutTree> listTreeItem = value;
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if ( element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
yield ExercisePlanReady();
|
||||
} else if (event is ExercisePlanUpdateExercise) {
|
||||
yield ExercisePlanReady();
|
||||
} else if (event is ExercisePlanSave) {
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() == 0) {
|
||||
throw Exception("Please select an exercise");
|
||||
} else {
|
||||
yield ExercisePlanLoading();
|
||||
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
|
||||
exercisePlanRepository.saveExercisePlan();
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
} on Exception catch (e) {
|
||||
yield ExercisePlanError(message: e.toString());
|
||||
}
|
||||
|
||||
@@ -11,21 +11,16 @@ class ExercisePlanLoad extends ExercisePlanEvent {
|
||||
const ExercisePlanLoad();
|
||||
}
|
||||
|
||||
class ExercisePlanUpdate extends ExercisePlanEvent {
|
||||
final WorkoutTree workoutTree;
|
||||
const ExercisePlanUpdate({this.workoutTree});
|
||||
|
||||
// update UI
|
||||
class ExercisePlanUpdateUI extends ExercisePlanEvent {
|
||||
final WorkoutMenuTree workoutTree;
|
||||
const ExercisePlanUpdateUI({this.workoutTree});
|
||||
|
||||
@override
|
||||
List<Object> get props => [workoutTree];
|
||||
}
|
||||
|
||||
class ExercisePlanAddExercise extends ExercisePlanEvent {
|
||||
final ExerciseType exerciseType;
|
||||
const ExercisePlanAddExercise({this.exerciseType});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseType];
|
||||
}
|
||||
|
||||
class ExercisePlanRemoveExercise extends ExercisePlanEvent {
|
||||
final ExercisePlanDetail exercisePlanDetail;
|
||||
@@ -35,15 +30,10 @@ class ExercisePlanRemoveExercise extends ExercisePlanEvent {
|
||||
List<Object> get props => [exercisePlanDetail];
|
||||
}
|
||||
|
||||
class ExercisePlanUpdateExercise extends ExercisePlanEvent {
|
||||
class ExercisePlanAddExercise extends ExercisePlanEvent {
|
||||
final ExercisePlanDetail exercisePlanDetail;
|
||||
const ExercisePlanUpdateExercise({this.exercisePlanDetail});
|
||||
const ExercisePlanAddExercise({this.exercisePlanDetail});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exercisePlanDetail];
|
||||
}
|
||||
|
||||
class ExercisePlanSave extends ExercisePlanEvent {
|
||||
const ExercisePlanSave();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user