wt1.1.2 new treeview, bar chart for muscle development
This commit is contained in:
@@ -0,0 +1,292 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:aitrainer_app/localization/app_language.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:aitrainer_app/util/calculate.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
|
||||
part 'development_by_muscle_event.dart';
|
||||
|
||||
part 'development_by_muscle_state.dart';
|
||||
|
||||
class DateRate {
|
||||
static String daily = "daily";
|
||||
static String weekly = "weekly";
|
||||
static String monthly = "monthly";
|
||||
static String yearly = "yearly";
|
||||
}
|
||||
|
||||
class DiagramType {
|
||||
static String sumMass = "sumMass";
|
||||
static String oneRepMax = "oneRepMax";
|
||||
static String percent = "percent";
|
||||
}
|
||||
|
||||
class ChartDataExtended {
|
||||
final List<BarChartGroupData> data;
|
||||
final double interval;
|
||||
final int gridInterval;
|
||||
|
||||
const ChartDataExtended({this.data, this.interval, this.gridInterval});
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{
|
||||
"data": data.toString(),
|
||||
"interval" : interval.toString(),
|
||||
"gridInterval" : gridInterval,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleBloc extends Bloc<DevelopmentByMuscleEvent, DevelopmentByMuscleState> with Calculate, Common {
|
||||
final WorkoutTreeRepository workoutTreeRepository;
|
||||
final ExerciseRepository exerciseRepository = ExerciseRepository();
|
||||
LinkedHashMap<int, ChartDataExtended> listChartData = LinkedHashMap();
|
||||
List<BarChartGroupData> chartData;
|
||||
String diagramType = DiagramType.sumMass;
|
||||
String dateRate = DateRate.daily;
|
||||
double basePercent = 0;
|
||||
|
||||
@override
|
||||
DevelopmentByMuscleBloc({
|
||||
this.workoutTreeRepository}) :
|
||||
super(DevelopmentByMuscleStateInitial());
|
||||
|
||||
Future<void> getData() async {
|
||||
|
||||
workoutTreeRepository.sortedTree = null;
|
||||
workoutTreeRepository.sortByMuscleType();
|
||||
|
||||
workoutTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutMenuTree> listWorkoutTree = value;
|
||||
listWorkoutTree.forEach((workoutTree) {
|
||||
workoutTree.selected = false;
|
||||
});
|
||||
});
|
||||
|
||||
this.getChartData();
|
||||
|
||||
}
|
||||
|
||||
void getChartData() {
|
||||
List<Exercise> exercises = exerciseRepository.getExerciseList();
|
||||
exercises.sort( (a, b) => a.exerciseTypeId.compareTo(b.exerciseTypeId));
|
||||
exercises = this.groupByDate(exercises);
|
||||
|
||||
int origExerciseTypeId = 0;
|
||||
int x = 0;
|
||||
chartData = List();
|
||||
double maxData = 0;
|
||||
double minData = 9999999999999;
|
||||
exercises.forEach((exercise) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
if (origExerciseTypeId != exercise.exerciseTypeId && diagramType == DiagramType.percent) {
|
||||
this.basePercent = getBasePercent(exercise);
|
||||
}
|
||||
double diagramValue = this.getDiagramValue(exercise);
|
||||
|
||||
if (maxData < diagramValue) {
|
||||
maxData = diagramValue;
|
||||
}
|
||||
if (minData > diagramValue) {
|
||||
minData = diagramValue;
|
||||
}
|
||||
//print("exercise " + exercise.exerciseTypeId.toString() + " d " + getDateFormat(exercise.dateAdd) + " mass " + sumMass.toString());
|
||||
//print("date " + exercise.dateAdd.toIso8601String() + " epoch " + exercise.dateAdd.millisecondsSinceEpoch.toString() );
|
||||
BarChartGroupData data = BarChartGroupData(
|
||||
x: exercise.dateAdd.millisecondsSinceEpoch,
|
||||
barRods: [
|
||||
BarChartRodData(y: diagramValue, width: 12, color: Colors.lightBlue)
|
||||
]
|
||||
);
|
||||
if (origExerciseTypeId != exercise.exerciseTypeId) {
|
||||
if (origExerciseTypeId == 0) {
|
||||
origExerciseTypeId = exercise.exerciseTypeId;
|
||||
chartData.add(data);
|
||||
} else {
|
||||
double dInterval = ((maxData + minData) / 8).roundToDouble();
|
||||
int gridInterval = (dInterval / 3).floor();
|
||||
ChartDataExtended extended = ChartDataExtended(
|
||||
data: chartData, interval: dInterval, gridInterval: gridInterval);
|
||||
listChartData[origExerciseTypeId] = extended;
|
||||
maxData = 0;
|
||||
minData = 9999999999999;
|
||||
chartData = List();
|
||||
chartData.add(data);
|
||||
origExerciseTypeId = exercise.exerciseTypeId;
|
||||
}
|
||||
} else {
|
||||
origExerciseTypeId = exercise.exerciseTypeId;
|
||||
chartData.add(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
listChartData.forEach((key, value) {
|
||||
print ("typeid " + key.toString() + " chardata " + value.toJson().toString());
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
String getDatePart(DateTime date) {
|
||||
String datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);;
|
||||
if ( this.dateRate == DateRate.weekly ) {
|
||||
datePart = weekNumber(date).toString();
|
||||
} else if ( this.dateRate == DateRate.monthly ) {
|
||||
datePart = DateFormat('MMM', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if ( this.dateRate == DateRate.yearly ) {
|
||||
datePart = DateFormat('y', AppLanguage().appLocal.toString()).format(date);
|
||||
} else if ( this.dateRate == DateRate.daily ) {
|
||||
datePart = DateFormat('MM.dd', AppLanguage().appLocal.toString()).format(date);
|
||||
}
|
||||
return datePart;
|
||||
}
|
||||
|
||||
List<Exercise> groupByDate(List<Exercise> exercises) {
|
||||
List<Exercise> groupedExercises = List();
|
||||
|
||||
String origDatePart;
|
||||
|
||||
int countExercises = 0;
|
||||
double sumQuantity = 0;
|
||||
double maxQuantity = 0;
|
||||
Exercise origExercise;
|
||||
exercises.forEach((exercise) {
|
||||
String exerciseDatePart = getDatePart(exercise.dateAdd);
|
||||
if ( origExercise != null ) {
|
||||
if ( origExercise.exerciseTypeId != exercise.exerciseTypeId || origDatePart != exerciseDatePart ) {
|
||||
Exercise newExercise = origExercise.copy();
|
||||
newExercise.datePart = origDatePart;
|
||||
if (this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent) {
|
||||
newExercise.quantity = maxQuantity;
|
||||
} else {
|
||||
newExercise.quantity = sumQuantity / countExercises;
|
||||
}
|
||||
groupedExercises.add(newExercise);
|
||||
countExercises = 0;
|
||||
sumQuantity = 0;
|
||||
maxQuantity = 0;
|
||||
}
|
||||
}
|
||||
origExercise = exercise;
|
||||
origDatePart = exerciseDatePart;
|
||||
|
||||
double newQuantity = getQuantityByDate(exercise);
|
||||
sumQuantity += newQuantity;
|
||||
if (maxQuantity < newQuantity) {
|
||||
maxQuantity = newQuantity;
|
||||
}
|
||||
countExercises++;
|
||||
|
||||
});
|
||||
|
||||
groupedExercises.forEach((element) {
|
||||
print("grouped " + element.toJson().toString());
|
||||
});
|
||||
|
||||
|
||||
return groupedExercises;
|
||||
}
|
||||
|
||||
double getQuantityByDate(Exercise exercise) {
|
||||
double sum = 0;
|
||||
if ( this.diagramType == DiagramType.sumMass ) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
sum = exercise.quantity * exercise.unitQuantity;
|
||||
} else {
|
||||
sum = exercise.quantity;
|
||||
}
|
||||
} else if ( this.diagramType == DiagramType.oneRepMax || this.diagramType == DiagramType.percent ) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
sum = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
} else {
|
||||
sum = exercise.quantity;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
double getBasePercent(Exercise exercise) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
this.basePercent = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
} else {
|
||||
this.basePercent = exercise.quantity;
|
||||
}
|
||||
//print("Base percent of " + exercise.exerciseTypeId.toString() + ": " + basePercent.toString());
|
||||
return this.basePercent;
|
||||
}
|
||||
|
||||
double getDiagramValue(Exercise exercise) {
|
||||
double value = 0;
|
||||
/*if ( diagramType == DiagramType.sumMass) {
|
||||
value = exercise.quantity;
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
value *= exercise.unitQuantity;
|
||||
}
|
||||
} else if ( diagramType == DiagramType.oneRepMax) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
value = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
}
|
||||
} else if ( diagramType == DiagramType.percent) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
double oneRepMax = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
value = (oneRepMax / this.basePercent) * 100;
|
||||
//print("Percent of " + exercise.exerciseTypeId.toString() + ": " + value.toString() + " date " + exercise.dateAdd.toIso8601String() + " 1RM " + oneRepMax.toString());
|
||||
} else {
|
||||
value = (exercise.quantity / this.basePercent ) * 100;
|
||||
}*/
|
||||
|
||||
if ( diagramType == DiagramType.percent) {
|
||||
if ( exercise.unitQuantity != null ) {
|
||||
double oneRepMax = calculate1RM(exercise.quantity, exercise.unitQuantity);
|
||||
value = (oneRepMax / this.basePercent) * 100;
|
||||
//print("Percent of " + exercise.exerciseTypeId.toString() + ": " + value.toString() + " date " + exercise.dateAdd.toIso8601String() + " 1RM " + oneRepMax.toString());
|
||||
} else {
|
||||
value = (exercise.quantity / this.basePercent ) * 100;
|
||||
}
|
||||
} else {
|
||||
return exercise.quantity;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
String getDateFormat(DateTime datetime) {
|
||||
return DateFormat('yMd', AppLanguage().appLocal.toString()).format(datetime);
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<DevelopmentByMuscleState> mapEventToState(DevelopmentByMuscleEvent event) async* {
|
||||
try {
|
||||
if (event is DevelopmentByMuscleLoad) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
await getData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
} else if ( event is DevelopmentByMuscleDiagramTypeChange ) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
String type = event.diagramType;
|
||||
this.diagramType = type;
|
||||
getChartData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
} else if ( event is DevelopmentByMuscleDateRateChange ) {
|
||||
yield DevelopmentByMuscleLoadingState();
|
||||
String dateRate = event.dateRate;
|
||||
this.dateRate = dateRate;
|
||||
getChartData();
|
||||
yield DevelopmentByMuscleReadyState();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield DevelopmentByMuscleErrorState(message: e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
part of 'development_by_muscle_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class DevelopmentByMuscleEvent extends Equatable {
|
||||
const DevelopmentByMuscleEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleLoad extends DevelopmentByMuscleEvent {
|
||||
const DevelopmentByMuscleLoad();
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleDateRateChange extends DevelopmentByMuscleEvent {
|
||||
final String dateRate;
|
||||
const DevelopmentByMuscleDateRateChange({this.dateRate});
|
||||
|
||||
@override
|
||||
List<Object> get props => [dateRate];
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleDiagramTypeChange extends DevelopmentByMuscleEvent {
|
||||
final String diagramType;
|
||||
const DevelopmentByMuscleDiagramTypeChange({this.diagramType});
|
||||
|
||||
@override
|
||||
List<Object> get props => [diagramType];
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
part of 'development_by_muscle_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class DevelopmentByMuscleState extends Equatable{
|
||||
const DevelopmentByMuscleState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleStateInitial extends DevelopmentByMuscleState {
|
||||
const DevelopmentByMuscleStateInitial();
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleLoadingState extends DevelopmentByMuscleState {
|
||||
const DevelopmentByMuscleLoadingState();
|
||||
}
|
||||
|
||||
class DevelopmentByMuscleReadyState extends DevelopmentByMuscleState {
|
||||
const DevelopmentByMuscleReadyState();
|
||||
}
|
||||
|
||||
|
||||
class DevelopmentByMuscleErrorState extends DevelopmentByMuscleState {
|
||||
final String message;
|
||||
const DevelopmentByMuscleErrorState({this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/model/workout_tree.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:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
@@ -8,7 +8,7 @@ import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
class ExerciseAddByPlanFormBloc extends FormBloc<String, String> {
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final ExercisePlanRepository exercisePlanRepository;
|
||||
final WorkoutTree workoutTree;
|
||||
final WorkoutMenuTree workoutTree;
|
||||
final customerId;
|
||||
Customer customer;
|
||||
int step = 1;
|
||||
@@ -40,12 +40,12 @@ class ExerciseAddByPlanFormBloc extends FormBloc<String, String> {
|
||||
} else if ( Cache().getTrainee().customerId == customerId) {
|
||||
customer = Cache().getTrainee();
|
||||
}
|
||||
exercisePlanRepository.setActualPlanDetail(workoutTree.exerciseType);
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
exerciseRepository.customer = customer;
|
||||
countSteps = exercisePlanRepository.actualPlanDetail.serie;
|
||||
countSteps = exercisePlanRepository.getActualPlanDetail().serie;
|
||||
|
||||
unitQuantity1Field.updateInitialValue(exercisePlanRepository.actualPlanDetail.weightEquation);
|
||||
quantity1Field.updateInitialValue(exercisePlanRepository.actualPlanDetail.repeats.toString());
|
||||
unitQuantity1Field.updateInitialValue(exercisePlanRepository.getActualPlanDetail().weightEquation);
|
||||
quantity1Field.updateInitialValue(exercisePlanRepository.getActualPlanDetail().repeats.toString());
|
||||
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class ExerciseAddByPlanFormBloc extends FormBloc<String, String> {
|
||||
exerciseRepository.setUnitQuantity(unitQuantity1Field.valueToDouble);
|
||||
exerciseRepository.setQuantity(quantity1Field.valueToDouble);
|
||||
exerciseRepository.exercise.exercisePlanDetailId =
|
||||
exercisePlanRepository.actualPlanDetail.exercisePlanDetailId;
|
||||
exercisePlanRepository.getActualPlanDetail().exercisePlanDetailId;
|
||||
exerciseRepository.exercise.unit = workoutTree.exerciseType.unit;
|
||||
workoutTree.executed = true;
|
||||
print("On Submitting Add Exercise By Plan " + exerciseRepository.exercise.toJson().toString());
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_tree.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:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -13,12 +12,11 @@ part 'exercise_by_plan_event.dart';
|
||||
part 'exercise_by_plan_state.dart';
|
||||
|
||||
class ExerciseByPlanBloc extends Bloc<ExerciseByPlanEvent, ExerciseByPlanState> {
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final WorkoutTreeRepository menuTreeRepository;
|
||||
final ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
int customerId;
|
||||
@override
|
||||
ExerciseByPlanBloc({this.exerciseRepository, this.menuTreeRepository}) : super(ExerciseByPlanStateInitial());
|
||||
ExerciseByPlanBloc({this.menuTreeRepository}) : super(ExerciseByPlanStateInitial());
|
||||
|
||||
Future<void> getData() async {
|
||||
exercisePlanRepository.setCustomerId(customerId);
|
||||
@@ -28,11 +26,11 @@ class ExerciseByPlanBloc extends Bloc<ExerciseByPlanEvent, ExerciseByPlanState>
|
||||
menuTreeRepository.sortByMuscleType();
|
||||
|
||||
menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutTree> listWorkoutTree = value;
|
||||
List<WorkoutMenuTree> listWorkoutTree = value;
|
||||
listWorkoutTree.forEach((workoutTree) {
|
||||
workoutTree.selected = false;
|
||||
if (exercisePlanRepository.exercisePlanDetails.length > 0) {
|
||||
if (exercisePlanRepository.exercisePlanDetails[workoutTree.exerciseTypeId] != null) {
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() > 0) {
|
||||
if (exercisePlanRepository.getExercisePlanDetailByExerciseId(workoutTree.exerciseTypeId) != null) {
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/workout_tree.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:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -15,11 +13,10 @@ part 'exercise_plan_state.dart';
|
||||
|
||||
class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
final WorkoutTreeRepository menuTreeRepository;
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
ExercisePlanRepository exercisePlanRepository = ExercisePlanRepository();
|
||||
int customerId;
|
||||
|
||||
ExercisePlanBloc({this.exerciseRepository, this.menuTreeRepository}) : super(ExercisePlanInitial());
|
||||
ExercisePlanBloc({this.menuTreeRepository}) : super(ExercisePlanInitial());
|
||||
|
||||
Future<void> getData() async {
|
||||
exercisePlanRepository.setCustomerId(customerId);
|
||||
@@ -29,12 +26,11 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
menuTreeRepository.sortByMuscleType();
|
||||
|
||||
menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutTree> listWorkoutTree = value;
|
||||
List<WorkoutMenuTree> listWorkoutTree = value;
|
||||
listWorkoutTree.forEach((workoutTree) {
|
||||
workoutTree.selected = false;
|
||||
if (exercisePlanRepository.exercisePlanDetails.length > 0) {
|
||||
if (exercisePlanRepository.exercisePlanDetails[workoutTree.exerciseTypeId] != null) {
|
||||
//print("bingo");
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() > 0) {
|
||||
if (exercisePlanRepository.getExercisePlanDetailByExerciseId(workoutTree.exerciseTypeId) != null) {
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
}
|
||||
@@ -42,6 +38,8 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
});
|
||||
}
|
||||
|
||||
void setExercisePlanRepository(ExercisePlanRepository repo ) => exercisePlanRepository = repo;
|
||||
|
||||
@override
|
||||
Stream<ExercisePlanState> mapEventToState(ExercisePlanEvent event) async* {
|
||||
try {
|
||||
@@ -50,38 +48,62 @@ class ExercisePlanBloc extends Bloc<ExercisePlanEvent, ExercisePlanState> {
|
||||
await this.getData();
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
if (event is ExercisePlanUpdate) {
|
||||
|
||||
if (event is ExercisePlanUpdateUI) {
|
||||
yield ExercisePlanLoading();
|
||||
WorkoutTree workoutTree = event.workoutTree;
|
||||
|
||||
WorkoutMenuTree workoutTree = event.workoutTree;
|
||||
if (workoutTree != null) {
|
||||
exercisePlanRepository.addExerciseTypeToPlan(workoutTree.exerciseType);
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType);
|
||||
workoutTree.selected = true;
|
||||
}
|
||||
|
||||
yield ExercisePlanReady();
|
||||
} else if (event is ExercisePlanRemoveExercise) {
|
||||
}
|
||||
|
||||
else if (event is ExercisePlanAddExercise) {
|
||||
yield ExercisePlanLoading();
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.removeExerciseTypeFromPlan(planDetail.exerciseType);
|
||||
exercisePlanRepository.actualPlanDetail = planDetail;
|
||||
|
||||
/*if ( exercisePlanRepository.exercisePlanDetails[planDetail.exerciseTypeId] == null ) {
|
||||
print("Add plan detail " + planDetail.toJson().toString());
|
||||
exercisePlanRepository.actualPlanDetail.change = ExercisePlanDetailChange.add;
|
||||
} else {
|
||||
print("Update plan detail " + planDetail.toJson().toString());
|
||||
exercisePlanRepository.actualPlanDetail.change = ExercisePlanDetailChange.update;
|
||||
}
|
||||
exercisePlanRepository.addDetailToPlan();*/
|
||||
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
|
||||
await exercisePlanRepository.saveExercisePlan();
|
||||
}
|
||||
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
|
||||
else if (event is ExercisePlanRemoveExercise) {
|
||||
yield ExercisePlanLoading();
|
||||
ExercisePlanDetail planDetail = event.exercisePlanDetail;
|
||||
exercisePlanRepository.removeExerciseTypeFromPlanByExerciseTypeId(planDetail.exerciseTypeId);
|
||||
|
||||
this.menuTreeRepository.sortedTree.forEach((key, value) {
|
||||
List<WorkoutTree> listTreeItem = value;
|
||||
List<WorkoutMenuTree> listTreeItem = value;
|
||||
listTreeItem.forEach((element) {
|
||||
if ( element.exerciseType.exerciseTypeId == planDetail.exerciseTypeId) {
|
||||
element.selected = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
yield ExercisePlanReady();
|
||||
} else if (event is ExercisePlanUpdateExercise) {
|
||||
yield ExercisePlanReady();
|
||||
} else if (event is ExercisePlanSave) {
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() == 0) {
|
||||
throw Exception("Please select an exercise");
|
||||
} else {
|
||||
yield ExercisePlanLoading();
|
||||
|
||||
if (exercisePlanRepository.getExercisePlanDetailSize() != 0) {
|
||||
exercisePlanRepository.saveExercisePlan();
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
yield ExercisePlanReady();
|
||||
}
|
||||
|
||||
} on Exception catch (e) {
|
||||
yield ExercisePlanError(message: e.toString());
|
||||
}
|
||||
|
||||
@@ -11,21 +11,16 @@ class ExercisePlanLoad extends ExercisePlanEvent {
|
||||
const ExercisePlanLoad();
|
||||
}
|
||||
|
||||
class ExercisePlanUpdate extends ExercisePlanEvent {
|
||||
final WorkoutTree workoutTree;
|
||||
const ExercisePlanUpdate({this.workoutTree});
|
||||
|
||||
// update UI
|
||||
class ExercisePlanUpdateUI extends ExercisePlanEvent {
|
||||
final WorkoutMenuTree workoutTree;
|
||||
const ExercisePlanUpdateUI({this.workoutTree});
|
||||
|
||||
@override
|
||||
List<Object> get props => [workoutTree];
|
||||
}
|
||||
|
||||
class ExercisePlanAddExercise extends ExercisePlanEvent {
|
||||
final ExerciseType exerciseType;
|
||||
const ExercisePlanAddExercise({this.exerciseType});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exerciseType];
|
||||
}
|
||||
|
||||
class ExercisePlanRemoveExercise extends ExercisePlanEvent {
|
||||
final ExercisePlanDetail exercisePlanDetail;
|
||||
@@ -35,15 +30,10 @@ class ExercisePlanRemoveExercise extends ExercisePlanEvent {
|
||||
List<Object> get props => [exercisePlanDetail];
|
||||
}
|
||||
|
||||
class ExercisePlanUpdateExercise extends ExercisePlanEvent {
|
||||
class ExercisePlanAddExercise extends ExercisePlanEvent {
|
||||
final ExercisePlanDetail exercisePlanDetail;
|
||||
const ExercisePlanUpdateExercise({this.exercisePlanDetail});
|
||||
const ExercisePlanAddExercise({this.exercisePlanDetail});
|
||||
|
||||
@override
|
||||
List<Object> get props => [exercisePlanDetail];
|
||||
}
|
||||
|
||||
class ExercisePlanSave extends ExercisePlanEvent {
|
||||
const ExercisePlanSave();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:aitrainer_app/bloc/exercise_plan/exercise_plan_bloc.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_plan_repository.dart';
|
||||
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
||||
|
||||
@@ -36,29 +37,29 @@ class ExercisePlanCustomerFormBloc extends FormBloc<String, String> {
|
||||
weightField
|
||||
]);
|
||||
|
||||
String repeatsInitial = exercisePlanRepository.actualPlanDetail != null &&
|
||||
exercisePlanRepository.actualPlanDetail.repeats != null ?
|
||||
exercisePlanRepository.actualPlanDetail.repeats.toString() : "12";
|
||||
String repeatsInitial = exercisePlanRepository.getActualPlanDetail() != null &&
|
||||
exercisePlanRepository.getActualPlanDetail().repeats != null ?
|
||||
exercisePlanRepository.getActualPlanDetail().repeats.toString() : "12";
|
||||
quantityField.updateInitialValue(repeatsInitial);
|
||||
|
||||
String serieInitial = exercisePlanRepository.actualPlanDetail != null &&
|
||||
exercisePlanRepository.actualPlanDetail.serie != null ?
|
||||
exercisePlanRepository.actualPlanDetail.serie.toString() : "3";
|
||||
String serieInitial = exercisePlanRepository.getActualPlanDetail() != null &&
|
||||
exercisePlanRepository.getActualPlanDetail().serie != null ?
|
||||
exercisePlanRepository.getActualPlanDetail().serie.toString() : "3";
|
||||
serieField.updateInitialValue(serieInitial);
|
||||
|
||||
String weightInitial = exercisePlanRepository.actualPlanDetail != null &&
|
||||
exercisePlanRepository.actualPlanDetail.weightEquation != null ?
|
||||
exercisePlanRepository.actualPlanDetail.weightEquation : "30";
|
||||
String weightInitial = exercisePlanRepository.getActualPlanDetail() != null &&
|
||||
exercisePlanRepository.getActualPlanDetail().weightEquation != null ?
|
||||
exercisePlanRepository.getActualPlanDetail().weightEquation : "30";
|
||||
weightField.updateInitialValue(weightInitial);
|
||||
|
||||
quantityField.onValueChanges(onData: (previous, current) async* {
|
||||
exercisePlanRepository.actualPlanDetail.repeats = current.valueToInt;
|
||||
exercisePlanRepository.getActualPlanDetail().repeats = current.valueToInt;
|
||||
});
|
||||
serieField.onValueChanges(onData: (previous, current) async* {
|
||||
exercisePlanRepository.actualPlanDetail.serie = current.valueToInt;
|
||||
exercisePlanRepository.getActualPlanDetail().serie = current.valueToInt;
|
||||
});
|
||||
weightField.onValueChanges(onData: (previous, current) async* {
|
||||
exercisePlanRepository.actualPlanDetail.weightEquation = current.value;
|
||||
exercisePlanRepository.getActualPlanDetail().weightEquation = current.value;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,12 +70,16 @@ class ExercisePlanCustomerFormBloc extends FormBloc<String, String> {
|
||||
emitLoading(progress: 30);
|
||||
// Emit either Loaded or Error
|
||||
|
||||
exercisePlanRepository.actualPlanDetail.repeats = quantityField.valueToInt;
|
||||
exercisePlanRepository.actualPlanDetail.serie = serieField.valueToInt;
|
||||
exercisePlanRepository.actualPlanDetail.weightEquation = weightField.value;
|
||||
|
||||
exercisePlanRepository.addToPlan();
|
||||
planBloc.add(ExercisePlanUpdate());
|
||||
exercisePlanRepository.getActualPlanDetail().repeats = quantityField.valueToInt;
|
||||
exercisePlanRepository.getActualPlanDetail().serie = serieField.valueToInt;
|
||||
exercisePlanRepository.getActualPlanDetail().weightEquation = weightField.value;
|
||||
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()));
|
||||
|
||||
emitSuccess(canSubmitAgain: false);
|
||||
} on Exception catch (ex) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/model/workout_tree.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/workout_tree_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
@@ -17,7 +17,7 @@ class MenuLoading extends MenuState {
|
||||
}
|
||||
|
||||
class MenuReady extends MenuState {
|
||||
final WorkoutTree workoutTree;
|
||||
final WorkoutMenuTree workoutTree;
|
||||
|
||||
const MenuReady({this.workoutTree});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user