WT 1.1.26+3 bloc migration
This commit is contained in:
@@ -20,7 +20,72 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
late int customerId;
|
||||
|
||||
ExercisePlanBloc({required this.menuTreeRepository}) : super(ExercisePlanInitial());
|
||||
ExercisePlanBloc({required this.menuTreeRepository}) : super(ExercisePlanInitial()) {
|
||||
on<ExercisePlanLoad>(_onLoad);
|
||||
on<ExercisePlanUpdateUI>(_onUpdateUI);
|
||||
on<ExercisePlanAddExercise>(_onAddExercise);
|
||||
on<ExercisePlanRemoveExercise>(_onRemoveExercise);
|
||||
}
|
||||
|
||||
void _onLoad(ExercisePlanLoad event, Emitter<ExercisePlanState> emit) async {
|
||||
if (Cache().userLoggedIn == null || Cache().userLoggedIn!.customerId == null) {
|
||||
throw Exception("Please log in");
|
||||
}
|
||||
emit(ExercisePlanLoading());
|
||||
customerId = Cache().userLoggedIn!.customerId!;
|
||||
await this.getData();
|
||||
Track().track(TrackingEvent.my_custom_exercise_plan);
|
||||
emit(ExercisePlanReady());
|
||||
}
|
||||
|
||||
void _onUpdateUI(ExercisePlanUpdateUI event, Emitter<ExercisePlanState> emit) {
|
||||
emit(ExercisePlanLoading());
|
||||
WorkoutMenuTree workoutTree = event.workoutTree;
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType!);
|
||||
workoutTree.selected = true;
|
||||
emit(ExercisePlanReady());
|
||||
}
|
||||
|
||||
void _onAddExercise(ExercisePlanAddExercise event, Emitter<ExercisePlanState> emit) async {
|
||||
emit(ExercisePlanLoading());
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.actualPlanDetail = planDetail;
|
||||
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
|
||||
await exercisePlanRepository.saveExercisePlan();
|
||||
}
|
||||
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
emit(ExercisePlanReady());
|
||||
}
|
||||
|
||||
void _onRemoveExercise(ExercisePlanRemoveExercise event, Emitter<ExercisePlanState> emit) async {
|
||||
emit(ExercisePlanLoading());
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(planDetail.exerciseTypeId);
|
||||
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
|
||||
await exercisePlanRepository.saveExercisePlan();
|
||||
Track().track(TrackingEvent.my_custom_exercise_plan_save);
|
||||
}
|
||||
emit(ExercisePlanReady());
|
||||
}
|
||||
|
||||
Future<void> getData() async {
|
||||
exercisePlanRepository.setCustomerId(customerId);
|
||||
@@ -45,71 +110,4 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
}
|
||||
|
||||
void setExercisePlanRepository(ExercisePlanRepository repo) => exercisePlanRepository = repo;
|
||||
|
||||
@override
|
||||
Stream<ExercisePlanState> mapEventToState(ExercisePlanEvent event) async* {
|
||||
try {
|
||||
if (event is ExercisePlanLoad) {
|
||||
if (Cache().userLoggedIn == null || Cache().userLoggedIn!.customerId == null) {
|
||||
throw Exception("Please log in");
|
||||
}
|
||||
yield ExercisePlanLoading();
|
||||
customerId = Cache().userLoggedIn!.customerId!;
|
||||
await this.getData();
|
||||
Track().track(TrackingEvent.my_custom_exercise_plan);
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
if (event is ExercisePlanUpdateUI) {
|
||||
yield ExercisePlanLoading();
|
||||
|
||||
WorkoutMenuTree workoutTree = event.workoutTree;
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType!);
|
||||
workoutTree.selected = true;
|
||||
|
||||
yield ExercisePlanReady();
|
||||
} else if (event is ExercisePlanAddExercise) {
|
||||
yield ExercisePlanLoading();
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.actualPlanDetail = planDetail;
|
||||
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
|
||||
await exercisePlanRepository.saveExercisePlan();
|
||||
}
|
||||
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
yield ExercisePlanReady();
|
||||
} else if (event is ExercisePlanRemoveExercise) {
|
||||
yield ExercisePlanLoading();
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(planDetail.exerciseTypeId);
|
||||
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if (element.exerciseType!.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
|
||||
exercisePlanRepository.saveExercisePlan();
|
||||
Track().track(TrackingEvent.my_custom_exercise_plan_save);
|
||||
}
|
||||
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield ExercisePlanError(message: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user