wt1.1.1 ExercisePlan + ExercisePlan detail, Trainee
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/menu_tree_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
part 'exercise_by_plan_event.dart';
|
||||
|
||||
part 'exercise_by_plan_state.dart';
|
||||
|
||||
class ExerciseByPlanBloc extends Bloc<ExerciseByPlanEvent, ExerciseByPlanState> {
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final MenuTreeRepository menuTreeRepository;
|
||||
final ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
int customerId;
|
||||
@override
|
||||
ExerciseByPlanBloc({this.exerciseRepository, this.menuTreeRepository}) : super(ExerciseByPlanStateInitial());
|
||||
|
||||
Future<void> getData() async {
|
||||
exercisePlanRepository.setCustomerId(customerId);
|
||||
await exercisePlanRepository.getLastExercisePlan();
|
||||
await exercisePlanRepository.getExercisePlanDetails();
|
||||
menuTreeRepository.sortedTree = null;
|
||||
menuTreeRepository.sortByMuscleType();
|
||||
|
||||
menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutTree> listWorkoutTree = value;
|
||||
listWorkoutTree.forEach((workoutTree) {
|
||||
workoutTree.selected = false;
|
||||
if (exercisePlanRepository.exercisePlanDetails.length > 0) {
|
||||
if (exercisePlanRepository.exercisePlanDetails[workoutTree.exerciseTypeId] != null) {
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<ExerciseByPlanState> mapEventToState(ExerciseByPlanEvent event) async* {
|
||||
try {
|
||||
if (event is ExerciseByPlanLoad) {
|
||||
yield ExerciseByPlanLoading();
|
||||
await this.getData();
|
||||
yield ExerciseByPlanReady();
|
||||
} else if (event is AddExerciseByPlanEvent) {
|
||||
yield ExerciseByPlanLoading();
|
||||
yield ExerciseByPlanReady();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield ExerciseByPlanError(message: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
part of 'exercise_by_plan_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExerciseByPlanEvent extends Equatable {
|
||||
const ExerciseByPlanEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class AddExerciseByPlanEvent extends ExerciseByPlanEvent {
|
||||
final ExerciseType exerciseType;
|
||||
const AddExerciseByPlanEvent({this.exerciseType});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseType];
|
||||
}
|
||||
|
||||
class ExerciseByPlanLoad extends ExerciseByPlanEvent {
|
||||
const ExerciseByPlanLoad();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
part of 'exercise_by_plan_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExerciseByPlanState extends Equatable {
|
||||
const ExerciseByPlanState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ExerciseByPlanStateInitial extends ExerciseByPlanState {
|
||||
const ExerciseByPlanStateInitial();
|
||||
}
|
||||
|
||||
class ExerciseByPlanLoading extends ExerciseByPlanState {
|
||||
const ExerciseByPlanLoading();
|
||||
}
|
||||
|
||||
// updated screen
|
||||
class ExerciseByPlanReady extends ExerciseByPlanState {
|
||||
const ExerciseByPlanReady();
|
||||
}
|
||||
|
||||
// error splash screen
|
||||
class ExerciseByPlanError extends ExerciseByPlanState {
|
||||
final String message;
|
||||
const ExerciseByPlanError({this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
Reference in New Issue
Block a user