wt1.1.2e NumberPicker
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/bloc/exercise_plan/exercise_plan_bloc.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
part 'exercise_plan_custom_add_event.dart';
|
||||
|
||||
part 'exercise_plan_custom_add_state.dart';
|
||||
|
||||
class ExercisePlanDetailChange {
|
||||
static const String add = "add";
|
||||
static const String delete = "delete";
|
||||
static const String update = "update";
|
||||
static const String deleted = "deleted";
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddBloc extends Bloc<ExercisePlanCustomAddEvent, ExercisePlanCustomAddState> {
|
||||
final ExercisePlanRepository exercisePlanRepository;
|
||||
final ExercisePlanBloc planBloc;
|
||||
final WorkoutMenuTree workoutMenuTree;
|
||||
|
||||
double quantity;
|
||||
double serie;
|
||||
double quantityUnit;
|
||||
|
||||
@override
|
||||
ExercisePlanCustomAddBloc({this.exercisePlanRepository, this.planBloc, this.workoutMenuTree}) : super(ExercisePlanCustomAddInitial()) {
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutMenuTree.exerciseType);
|
||||
quantity = exercisePlanRepository.getActualPlanDetail().repeats != null ?
|
||||
exercisePlanRepository.getActualPlanDetail().repeats.toDouble() : 12;
|
||||
serie = exercisePlanRepository.getActualPlanDetail().serie != null ?
|
||||
exercisePlanRepository.getActualPlanDetail().serie.toDouble() : 3;
|
||||
quantityUnit = exercisePlanRepository.getActualPlanDetail().weightEquation != null ?
|
||||
double.parse(exercisePlanRepository.getActualPlanDetail().weightEquation) : 30;
|
||||
|
||||
exercisePlanRepository.getActualPlanDetail().weightEquation = quantityUnit.toString();
|
||||
exercisePlanRepository.getActualPlanDetail().serie = serie.toInt();
|
||||
exercisePlanRepository.getActualPlanDetail().repeats = quantity.toInt();
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<ExercisePlanCustomAddState> mapEventToState(ExercisePlanCustomAddEvent event) async* {
|
||||
try {
|
||||
if (event is ExercisePlanCustomAddLoad) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddChangeSerie ) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
serie = event.quantity;
|
||||
exercisePlanRepository.getActualPlanDetail().serie = event.quantity.toInt();
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddChangeQuantity ) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
quantity = event.quantity;
|
||||
exercisePlanRepository.getActualPlanDetail().repeats = event.quantity.toInt();
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddChangeQuantityUnit ) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
quantityUnit = event.quantity;
|
||||
exercisePlanRepository.getActualPlanDetail().weightEquation = event.quantity.toStringAsFixed(0);
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddSubmit) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
if ( exercisePlanRepository.exercisePlanDetails[exercisePlanRepository.getActualPlanDetail()] == null ) {
|
||||
exercisePlanRepository.getActualPlanDetail().change = ExercisePlanDetailChange.add;
|
||||
} else {
|
||||
exercisePlanRepository.getActualPlanDetail().change = ExercisePlanDetailChange.update;
|
||||
}
|
||||
exercisePlanRepository.addDetailToPlan();
|
||||
planBloc.add(ExercisePlanAddExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()));
|
||||
yield ExercisePlanCustomAddReady();
|
||||
} else if ( event is ExercisePlanCustomAddRemove ) {
|
||||
yield ExercisePlanCustomAddLoading();
|
||||
print("Remove " + exercisePlanRepository.getActualPlanDetail().exerciseType.name);
|
||||
exercisePlanRepository.getActualPlanDetail().change = ExercisePlanDetailChange.delete;
|
||||
planBloc.add(ExercisePlanRemoveExercise(exercisePlanDetail: exercisePlanRepository.getActualPlanDetail()));
|
||||
|
||||
yield ExercisePlanCustomAddReady();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield ExercisePlanCustomAddError(message: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
part of 'exercise_plan_custom_add_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExercisePlanCustomAddEvent extends Equatable {
|
||||
const ExercisePlanCustomAddEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddLoad extends ExercisePlanCustomAddEvent {
|
||||
const ExercisePlanCustomAddLoad();
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddChangeSerie extends ExercisePlanCustomAddEvent {
|
||||
final double quantity;
|
||||
const ExercisePlanCustomAddChangeSerie({this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddChangeQuantity extends ExercisePlanCustomAddEvent {
|
||||
final double quantity;
|
||||
const ExercisePlanCustomAddChangeQuantity({this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddChangeQuantityUnit extends ExercisePlanCustomAddEvent {
|
||||
final double quantity;
|
||||
const ExercisePlanCustomAddChangeQuantityUnit({this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddSubmit extends ExercisePlanCustomAddEvent {
|
||||
const ExercisePlanCustomAddSubmit();
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddRemove extends ExercisePlanCustomAddEvent {
|
||||
const ExercisePlanCustomAddRemove();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
part of 'exercise_plan_custom_add_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExercisePlanCustomAddState extends Equatable {
|
||||
const ExercisePlanCustomAddState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddInitial extends ExercisePlanCustomAddState {
|
||||
const ExercisePlanCustomAddInitial();
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddLoading extends ExercisePlanCustomAddState {
|
||||
const ExercisePlanCustomAddLoading();
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddReady extends ExercisePlanCustomAddState {
|
||||
const ExercisePlanCustomAddReady();
|
||||
}
|
||||
|
||||
class ExercisePlanCustomAddError extends ExercisePlanCustomAddState {
|
||||
final String message;
|
||||
const ExercisePlanCustomAddError({this.message});
|
||||
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
Reference in New Issue
Block a user