wt1.1.2e NumberPicker
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
part 'exercise_execute_plan_event.dart';
|
||||
|
||||
part 'exercise_execute_plan_state.dart';
|
||||
|
||||
class ExerciseExecutePlanBloc extends Bloc<ExerciseExecutePlanEvent, ExerciseExecutePlanState> {
|
||||
final WorkoutTreeRepository menuTreeRepository;
|
||||
final ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
int customerId;
|
||||
@override
|
||||
ExerciseExecutePlanBloc({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<WorkoutMenuTree> listWorkoutTree = value;
|
||||
listWorkoutTree.forEach((workoutTree) {
|
||||
workoutTree.selected = false;
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() > 0) {
|
||||
if (exercisePlanRepository.getExercisePlanDetailByExerciseId(workoutTree.exerciseTypeId) != null) {
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<ExerciseExecutePlanState> mapEventToState(ExerciseExecutePlanEvent 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_execute_plan_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExerciseExecutePlanEvent extends Equatable {
|
||||
const ExerciseExecutePlanEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class AddExerciseByPlanEvent extends ExerciseExecutePlanEvent {
|
||||
final ExerciseType exerciseType;
|
||||
const AddExerciseByPlanEvent({this.exerciseType});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseType];
|
||||
}
|
||||
|
||||
class ExerciseByPlanLoad extends ExerciseExecutePlanEvent {
|
||||
const ExerciseByPlanLoad();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
part of 'exercise_execute_plan_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExerciseExecutePlanState extends Equatable {
|
||||
const ExerciseExecutePlanState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ExerciseByPlanStateInitial extends ExerciseExecutePlanState {
|
||||
const ExerciseByPlanStateInitial();
|
||||
}
|
||||
|
||||
class ExerciseByPlanLoading extends ExerciseExecutePlanState {
|
||||
const ExerciseByPlanLoading();
|
||||
}
|
||||
|
||||
// updated screen
|
||||
class ExerciseByPlanReady extends ExerciseExecutePlanState {
|
||||
const ExerciseByPlanReady();
|
||||
}
|
||||
|
||||
// error splash screen
|
||||
class ExerciseByPlanError extends ExerciseExecutePlanState {
|
||||
final String message;
|
||||
const ExerciseByPlanError({this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
Reference in New Issue
Block a user