1.1.22+3 corrections
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/sport.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/mautic_repository.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -29,8 +30,8 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
weight = this.customerRepository.getWeight() == 0 ? 60 : this.customerRepository.getWeight();
|
||||
height = this.customerRepository.getHeight() == 0 ? 170 : this.customerRepository.getHeight();
|
||||
|
||||
// selectedSport = customerRepository.getSport();
|
||||
//print("selected: $selectedFitnessItem sport: $selectedSport " + customerRepository.customer!.fitnessLevel.toString());
|
||||
selectedFitnessItem = customerRepository.fitnessLevel;
|
||||
selectedSport = customerRepository.getSport();
|
||||
}
|
||||
|
||||
Sport? selectedSport;
|
||||
@@ -95,6 +96,7 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
} else if (event is CustomerSportChange) {
|
||||
yield CustomerChangeLoading();
|
||||
selectedSport = event.sport;
|
||||
print("Selected Sport $selectedSport");
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerSaveFitness) {
|
||||
yield CustomerChangeLoading();
|
||||
@@ -137,6 +139,8 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
}
|
||||
|
||||
await customerRepository.saveCustomer();
|
||||
MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository);
|
||||
await mauticRepository.sendMauticDataChange();
|
||||
Cache().initBadges();
|
||||
yield CustomerSaveSuccess();
|
||||
} else {
|
||||
@@ -151,10 +155,6 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
bool validation() {
|
||||
if (customerRepository.customer == null) throw Exception("Customer object not defined");
|
||||
return true;
|
||||
/* return (emailValidation(customerRepository.customer!.email) == null) &&
|
||||
(passwordValidation(customerRepository.customer!.password) == null) &&
|
||||
(nameValidation(customerRepository.customer!.firstname) == null) &&
|
||||
(nameValidation(customerRepository.customer!.name) == null); */
|
||||
}
|
||||
|
||||
String? emailValidation(String? email) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'package:aitrainer_app/bloc/timer/timer_bloc.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -26,7 +27,6 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
late double initialRM;
|
||||
late double unitQuantity;
|
||||
late double quantity;
|
||||
late double origQuantity;
|
||||
late double oneRepQuantity;
|
||||
late double oneRepUnitQuantity;
|
||||
|
||||
@@ -36,6 +36,8 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
double scrollOffset = 0;
|
||||
late ExerciseTypeLocal exerciseTypeLocal;
|
||||
|
||||
List<Exercise> controlList = [];
|
||||
|
||||
@override
|
||||
ExerciseControlBloc({required this.exerciseRepository, required this.readonly, required this.timerBloc})
|
||||
: super(ExerciseControlInitial()) {
|
||||
@@ -53,29 +55,29 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
if (oneRepQuantity > 25) {
|
||||
quantity = 35;
|
||||
}
|
||||
origQuantity = quantity;
|
||||
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
Exercise exercise = Exercise();
|
||||
exercise.quantity = quantity;
|
||||
exercise.unitQuantity = unitQuantity;
|
||||
controlList.add(exercise);
|
||||
}
|
||||
|
||||
timerBloc.add(TimerStart(duration: 300));
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<ExerciseControlState> mapEventToState(ExerciseControlEvent event) async* {
|
||||
try {
|
||||
/* if (event is ExerciseControlLoad) {
|
||||
yield ExerciseControlLoading();
|
||||
step = 1;
|
||||
yield ExerciseControlReady();
|
||||
} else */
|
||||
if (event is ExerciseControlQuantityChange) {
|
||||
//yield ExerciseControlLoading();
|
||||
if (event.step == step) {
|
||||
exerciseRepository.setQuantity(event.quantity);
|
||||
quantity = event.quantity;
|
||||
controlList[step - 1].quantity = quantity;
|
||||
}
|
||||
//yield ExerciseControlReady();
|
||||
} else if (event is ExerciseControlUnitQuantityChange) {
|
||||
yield ExerciseControlLoading();
|
||||
print("event step ${event.step} quantity ${event.quantity}");
|
||||
@@ -85,7 +87,8 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
unitQuantity = event.quantity;
|
||||
quantity = calculateQuantityByUnitQuantity().toDouble();
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
origQuantity = quantity;
|
||||
controlList[step - 1].unitQuantity = event.quantity;
|
||||
controlList[step - 1].quantity = quantity;
|
||||
}
|
||||
yield ExerciseControlReady();
|
||||
} else if (event is ExerciseControlSubmit) {
|
||||
@@ -94,13 +97,11 @@ class ExerciseControlBloc extends Bloc<ExerciseControlEvent, ExerciseControlStat
|
||||
step++;
|
||||
scrollOffset = step * 400.0;
|
||||
|
||||
quantity = origQuantity;
|
||||
if (exerciseRepository.exercise!.quantity == null) {
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
}
|
||||
exerciseRepository.end = DateTime.now();
|
||||
await exerciseRepository.addExercise();
|
||||
//exerciseRepository.initExercise();
|
||||
|
||||
step <= 3 ? timerBloc.add(TimerStart(duration: 300)) : timerBloc.add(TimerEnd(duration: 300));
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
final CustomerRepository customerRepository;
|
||||
final MenuBloc menuBloc;
|
||||
late AnimationController bmiAnimationController;
|
||||
double quantity = 12;
|
||||
double unitQuantity = 30;
|
||||
double quantity = -1;
|
||||
double unitQuantity = -1;
|
||||
double bmi = 0;
|
||||
double bmr = 0;
|
||||
double goalBMI = 0;
|
||||
@@ -148,6 +148,10 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
yield ExerciseNewReady();
|
||||
} else if (event is ExerciseNewSubmit) {
|
||||
yield ExerciseNewLoading();
|
||||
if (quantity == -1 || unitQuantity == -1) {
|
||||
yield ExerciseNewReady();
|
||||
throw Exception("Please type in a real number");
|
||||
}
|
||||
exerciseRepository.end = DateTime.now();
|
||||
await exerciseRepository.addExercise();
|
||||
// exerciseRepository.initExercise();
|
||||
|
||||
@@ -2,8 +2,11 @@ import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/bloc/account/account_bloc.dart';
|
||||
import 'package:aitrainer_app/model/cache.dart';
|
||||
import 'package:aitrainer_app/model/customer.dart';
|
||||
import 'package:aitrainer_app/repository/customer_repository.dart';
|
||||
import 'package:aitrainer_app/repository/mautic_repository.dart';
|
||||
import 'package:aitrainer_app/repository/split_test_respository.dart';
|
||||
import 'package:aitrainer_app/repository/training_plan_repository.dart';
|
||||
import 'package:aitrainer_app/repository/user_repository.dart';
|
||||
import 'package:aitrainer_app/util/common.dart';
|
||||
import 'package:aitrainer_app/util/enums.dart';
|
||||
@@ -19,7 +22,7 @@ part 'login_state.dart';
|
||||
class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
final AccountBloc accountBloc;
|
||||
final UserRepository userRepository;
|
||||
final CustomerRepository customerRepository = CustomerRepository();
|
||||
late CustomerRepository? customerRepository;
|
||||
final SplitTestRepository splitTestRepository = SplitTestRepository();
|
||||
final BuildContext context;
|
||||
final bool isRegistration;
|
||||
@@ -30,7 +33,12 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
Color testColor = Colors.green[800]!;
|
||||
bool emailCheckbox = true;
|
||||
|
||||
LoginBloc({required this.accountBloc, required this.userRepository, required this.context, required this.isRegistration})
|
||||
LoginBloc(
|
||||
{required this.accountBloc,
|
||||
required this.userRepository,
|
||||
required this.context,
|
||||
required this.isRegistration,
|
||||
this.customerRepository})
|
||||
: super(LoginInitial()) {
|
||||
String colorString = splitTestRepository.getSplitTestValue("registration_skip");
|
||||
if (colorString == "red") {
|
||||
@@ -40,6 +48,9 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
if (emailCheckboxString == "0") {
|
||||
emailCheckbox = false;
|
||||
}
|
||||
if (customerRepository == null) {
|
||||
customerRepository = CustomerRepository();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -87,56 +98,44 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
yield LoginSuccess();
|
||||
} else if (event is RegistrationSubmit) {
|
||||
yield LoginLoading();
|
||||
/* if (!this.dataPolicyAllowed) {
|
||||
throw Exception("Please accept our data policy");
|
||||
} */
|
||||
|
||||
final String? validationError = validate();
|
||||
if (validationError != null) {
|
||||
yield LoginError(message: validationError);
|
||||
} else {
|
||||
await userRepository.addUser();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
customerRepository.customer!.emailSubscription = emailSubscription == true ? 1 : 0;
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "email");
|
||||
customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0;
|
||||
await afterRegistration("email");
|
||||
Cache().setLoginType(LoginType.email);
|
||||
yield LoginSuccess();
|
||||
}
|
||||
} else if (event is RegistrationFB) {
|
||||
yield LoginLoading();
|
||||
/* if (!this.dataPolicyAllowed) {
|
||||
throw Exception("Please accept our data policy");
|
||||
} */
|
||||
|
||||
Cache().setLoginType(LoginType.fb);
|
||||
await userRepository.addUserFB();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
customerRepository.customer!.emailSubscription = emailSubscription == true ? 1 : 0;
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "FB");
|
||||
customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0;
|
||||
await afterRegistration("FB");
|
||||
yield LoginSuccess();
|
||||
} else if (event is RegistrationGoogle) {
|
||||
yield LoginLoading();
|
||||
/* if (!this.dataPolicyAllowed) {
|
||||
throw Exception("Please accept our data policy");
|
||||
} */
|
||||
|
||||
Cache().setLoginType(LoginType.google);
|
||||
await userRepository.addUserGoogle();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
customerRepository.customer!.emailSubscription = emailSubscription == true ? 1 : 0;
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "Google");
|
||||
customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0;
|
||||
await afterRegistration("Google");
|
||||
yield LoginSuccess();
|
||||
} else if (event is RegistrationApple) {
|
||||
yield LoginLoading();
|
||||
/* if (!this.dataPolicyAllowed) {
|
||||
throw Exception("Please accept our data policy");
|
||||
} */
|
||||
|
||||
Cache().setLoginType(LoginType.apple);
|
||||
await userRepository.addUserApple();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
customerRepository.customer!.emailSubscription = emailSubscription == true ? 1 : 0;
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "Apple");
|
||||
customerRepository!.customer!.emailSubscription = emailSubscription == true ? 1 : 0;
|
||||
await afterRegistration("Apple");
|
||||
|
||||
yield LoginSuccess();
|
||||
} else if (event is DataProtectionClicked) {
|
||||
@@ -162,10 +161,23 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveCustomer() async {
|
||||
customerRepository.customer = Cache().userLoggedIn!;
|
||||
customerRepository.customer!.dataPolicyAllowed = 1;
|
||||
await customerRepository.saveCustomer();
|
||||
Future<void> afterRegistration(String event) async {
|
||||
Customer tempCustomer = customerRepository!.customer!;
|
||||
customerRepository!.customer = Cache().userLoggedIn!;
|
||||
customerRepository!.customer!.fitnessLevel = tempCustomer.fitnessLevel;
|
||||
customerRepository!.customer!.goal = tempCustomer.goal;
|
||||
customerRepository!.customer!.sex = tempCustomer.sex;
|
||||
customerRepository!.customer!.dataPolicyAllowed = 1;
|
||||
customerRepository!.customer!.emailSubscription = 1;
|
||||
customerRepository!.customer!.syncedDate = DateTime.now();
|
||||
customerRepository!.setCustomerProperty("Weight", tempCustomer.getProperty("Weight"));
|
||||
customerRepository!.setCustomerProperty("Height", tempCustomer.getProperty("Height"));
|
||||
await customerRepository!.saveCustomer();
|
||||
MauticRepository mauticRepository = MauticRepository(customerRepository: customerRepository!);
|
||||
await mauticRepository.sendMauticSubscription();
|
||||
TrainingPlanRepository trainingPlanRepository = TrainingPlanRepository();
|
||||
trainingPlanRepository.generateTrainingPlan();
|
||||
Track().track(TrackingEvent.registration, eventValue: event);
|
||||
}
|
||||
|
||||
String? emailValidation(String? email) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import 'package:aitrainer_app/model/customer_training_plan_details.dart';
|
||||
import 'package:aitrainer_app/model/exercise.dart';
|
||||
import 'package:aitrainer_app/model/exercise_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/exercise_type.dart';
|
||||
import 'package:aitrainer_app/model/training_plan.dart';
|
||||
import 'package:aitrainer_app/model/training_plan_detail.dart';
|
||||
import 'package:aitrainer_app/model/workout_menu_tree.dart';
|
||||
import 'package:aitrainer_app/repository/training_plan_repository.dart';
|
||||
import 'package:aitrainer_app/service/exercise_service.dart';
|
||||
@@ -29,6 +31,9 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
CustomerTrainingPlan? _myPlan;
|
||||
CustomerTrainingPlanDetails? _myDetail;
|
||||
|
||||
TrainingPlan? _myTrainingPlan;
|
||||
final List<String> trainingPlanDayNames = [];
|
||||
|
||||
bool started = false;
|
||||
final List<String> dayNames = [];
|
||||
bool restarting = false;
|
||||
@@ -38,6 +43,9 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
CustomerTrainingPlan? getMyPlan() => this._myPlan;
|
||||
setMyPlan(CustomerTrainingPlan? myPlan) => this._myPlan = myPlan;
|
||||
|
||||
TrainingPlan? getMyTrainingPlan() => this._myTrainingPlan;
|
||||
setMyTrainingPlan(TrainingPlan? myTrainingPlan) => this._myTrainingPlan = myTrainingPlan;
|
||||
|
||||
CustomerTrainingPlanDetails? getMyDetail() => this._myDetail;
|
||||
setMyDetail(CustomerTrainingPlanDetails? value) => this._myDetail = value;
|
||||
|
||||
@@ -88,6 +96,10 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
yield TrainingPlanReady();
|
||||
} else if (event is TrainingPlanSaveExercise) {
|
||||
yield TrainingPlanLoading();
|
||||
if (event.detail.repeats == -1) {
|
||||
yield TrainingPlanReady();
|
||||
throw Exception("Please type your repeats!");
|
||||
}
|
||||
if (event.detail.weight == -3) {
|
||||
print("DropSet");
|
||||
event.detail.state = ExercisePlanDetailState.finished;
|
||||
@@ -293,6 +305,83 @@ class TrainingPlanBloc extends Bloc<TrainingPlanEvent, TrainingPlanState> {
|
||||
getActiveDayIndex();
|
||||
}
|
||||
|
||||
void activateTrainingPlanDays() {
|
||||
if (_myTrainingPlan == null || _myTrainingPlan!.details == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
trainingPlanDayNames.clear();
|
||||
|
||||
String dayName = ".";
|
||||
_myTrainingPlan!.details!.forEach((element) {
|
||||
if (element.day != null && element.day != dayName) {
|
||||
trainingPlanDayNames.add(element.day!);
|
||||
dayName = element.day!;
|
||||
}
|
||||
});
|
||||
|
||||
if (trainingPlanDayNames.length == 0) {
|
||||
dayName = "";
|
||||
trainingPlanDayNames.add(dayName);
|
||||
}
|
||||
}
|
||||
|
||||
List<TrainingPlanDetail> trainingPlanDetailSummary(TrainingPlan plan, String dayName) {
|
||||
List<TrainingPlanDetail> details = [];
|
||||
TrainingPlanDetail? prev;
|
||||
plan.details!.forEach((element) {
|
||||
if (prev == null || element.exerciseTypeId != prev!.exerciseTypeId) {
|
||||
if (element.day! == dayName) {
|
||||
element.summary = getSummary(element);
|
||||
details.add(element);
|
||||
}
|
||||
prev = element;
|
||||
}
|
||||
});
|
||||
return details;
|
||||
}
|
||||
|
||||
List<TrainingPlanDetail> getAllTrainingPlanDetailsSameExercise(TrainingPlanDetail detail) {
|
||||
List<TrainingPlanDetail> list = [];
|
||||
getMyTrainingPlan()!.details!.forEach((element) {
|
||||
if (detail.exerciseTypeId == element.exerciseTypeId) {
|
||||
list.add(element);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
String getSummary(TrainingPlanDetail detail) {
|
||||
String summary = "";
|
||||
String set = "1";
|
||||
|
||||
set = detail.set.toString() + "/ ";
|
||||
List<TrainingPlanDetail> details = getAllTrainingPlanDetailsSameExercise(detail);
|
||||
int index = 0;
|
||||
|
||||
String quantities = "";
|
||||
|
||||
details.forEach((element) {
|
||||
String delimiter = ", ";
|
||||
if (index == 0) {
|
||||
delimiter = "";
|
||||
}
|
||||
if (element.repeats == -1) {
|
||||
quantities += delimiter + " MAX ";
|
||||
} else {
|
||||
quantities += delimiter + "${element.repeats}";
|
||||
}
|
||||
|
||||
index++;
|
||||
});
|
||||
|
||||
//quantities += " / ? kg";
|
||||
|
||||
summary = quantities;
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
void addExtraExerciseType(String name, String dayName) {
|
||||
if (Cache().getExerciseTypes() == null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user