wt1.1.2e NumberPicker
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/bloc/exercise_execute_plan/exercise_execute_plan_bloc.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.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:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
part 'exercise_execute_plan_add_event.dart';
|
||||
|
||||
part 'exercise_execute_plan_add_state.dart';
|
||||
|
||||
class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, ExerciseExecutePlanAddState> {
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final ExercisePlanRepository exercisePlanRepository;
|
||||
final WorkoutMenuTree workoutTree;
|
||||
final ExerciseExecutePlanBloc planBloc;
|
||||
final int customerId;
|
||||
|
||||
Customer customer;
|
||||
int step = 1;
|
||||
int countSteps = 1;
|
||||
|
||||
double quantity;
|
||||
double unitQuantity;
|
||||
|
||||
double scrollOffset = 0;
|
||||
|
||||
@override
|
||||
ExerciseExecutePlanAddBloc({
|
||||
this.exerciseRepository,
|
||||
this.exercisePlanRepository,
|
||||
this.customerId,
|
||||
this.workoutTree,
|
||||
this.planBloc}): super(ExerciseExecutePlanAddInitial()) {
|
||||
exerciseRepository.exerciseType = workoutTree.exerciseType;
|
||||
if ( Cache().userLoggedIn.customerId == customerId) {
|
||||
customer = Cache().userLoggedIn;
|
||||
} else if ( Cache().getTrainee().customerId == customerId) {
|
||||
customer = Cache().getTrainee();
|
||||
}
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
exerciseRepository.customer = customer;
|
||||
countSteps = exercisePlanRepository.getActualPlanDetail().serie;
|
||||
|
||||
unitQuantity = double.parse(exercisePlanRepository.getActualPlanDetail().weightEquation);
|
||||
quantity = exercisePlanRepository.getActualPlanDetail().repeats.toDouble();
|
||||
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<ExerciseExecutePlanAddState> mapEventToState(ExerciseExecutePlanAddEvent event) async* {
|
||||
try {
|
||||
if (event is ExerciseExecutePlanAddLoad) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
yield ExerciseExecutePlanAddReady();
|
||||
} else if (event is ExerciseExecutePlanAddChangeQuantity) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
quantity = event.quantity;
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
yield ExerciseExecutePlanAddReady();
|
||||
} else if (event is ExerciseExecutePlanAddChangeUnitQuantity) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
unitQuantity = event.quantity;
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
yield ExerciseExecutePlanAddReady();
|
||||
} else if (event is ExerciseExecutePlanAddSubmit) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
exerciseRepository.exercise.exercisePlanDetailId =
|
||||
exercisePlanRepository.getActualPlanDetail().exercisePlanDetailId;
|
||||
exerciseRepository.exercise.unit = workoutTree.exerciseType.unit;
|
||||
workoutTree.executed = true;
|
||||
print("On Submitting Exercise Execute Plan Add " + exerciseRepository.exercise.toJson().toString());
|
||||
await exerciseRepository.addExercise();
|
||||
step++;
|
||||
scrollOffset = step * 200.0;
|
||||
planBloc.add(ExerciseByPlanLoad());
|
||||
yield ExerciseExecutePlanAddReady();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield ExerciseExecutePlanAddError(message: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
part of 'exercise_execute_plan_add_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExerciseExecutePlanAddEvent extends Equatable {
|
||||
const ExerciseExecutePlanAddEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ExerciseExecutePlanAddLoad extends ExerciseExecutePlanAddEvent {
|
||||
const ExerciseExecutePlanAddLoad();
|
||||
}
|
||||
|
||||
class ExerciseExecutePlanAddChangeQuantity extends ExerciseExecutePlanAddEvent {
|
||||
final double quantity;
|
||||
const ExerciseExecutePlanAddChangeQuantity({this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
}
|
||||
|
||||
class ExerciseExecutePlanAddChangeUnitQuantity extends ExerciseExecutePlanAddEvent {
|
||||
final double quantity;
|
||||
const ExerciseExecutePlanAddChangeUnitQuantity({this.quantity});
|
||||
|
||||
@override
|
||||
List<Object> get props => [quantity];
|
||||
}
|
||||
|
||||
class ExerciseExecutePlanAddSubmit extends ExerciseExecutePlanAddEvent {
|
||||
const ExerciseExecutePlanAddSubmit();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
part of 'exercise_execute_plan_add_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class ExerciseExecutePlanAddState extends Equatable {
|
||||
const ExerciseExecutePlanAddState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ExerciseExecutePlanAddInitial extends ExerciseExecutePlanAddState {
|
||||
const ExerciseExecutePlanAddInitial();
|
||||
}
|
||||
|
||||
class ExerciseExecutePlanAddLoading extends ExerciseExecutePlanAddState {
|
||||
const ExerciseExecutePlanAddLoading();
|
||||
}
|
||||
|
||||
// updated screen
|
||||
class ExerciseExecutePlanAddReady extends ExerciseExecutePlanAddState {
|
||||
const ExerciseExecutePlanAddReady();
|
||||
}
|
||||
|
||||
// error splash screen
|
||||
class ExerciseExecutePlanAddError extends ExerciseExecutePlanAddState {
|
||||
final String message;
|
||||
const ExerciseExecutePlanAddError({this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
Reference in New Issue
Block a user