WT 1.1.11+3 Evaluation, null-safe fixes
This commit is contained in:
@@ -74,7 +74,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
yield AccountLoggedIn();
|
||||
} else if (event is AccountLogout) {
|
||||
await Cache().logout();
|
||||
//customerRepository.customer = null;
|
||||
customerRepository.customer = null;
|
||||
customerRepository.emptyTrainees();
|
||||
loggedIn = false;
|
||||
yield AccountLoggedOut();
|
||||
|
||||
@@ -9,6 +9,8 @@ import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../../model/fitness_state.dart';
|
||||
|
||||
part 'customer_change_event.dart';
|
||||
part 'customer_change_state.dart';
|
||||
|
||||
@@ -19,14 +21,40 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
double weight = 60;
|
||||
double height = 170;
|
||||
CustomerChangeBloc({required this.customerRepository}) : super(CustomerChangeInitial()) {
|
||||
year = this.customerRepository.customer.birthYear;
|
||||
if (this.customerRepository.customer == null) {
|
||||
this.customerRepository.createNew();
|
||||
}
|
||||
year = this.customerRepository.customer!.birthYear;
|
||||
if (year == null || year == 0) {
|
||||
year = 1990;
|
||||
}
|
||||
weight = this.customerRepository.getWeight() == 0 ? 60 : this.customerRepository.getWeight();
|
||||
height = this.customerRepository.getHeight() == 0 ? 170 : this.customerRepository.getHeight();
|
||||
|
||||
print("fitnesslevel " + customerRepository.customer!.fitnessLevel.toString());
|
||||
if (customerRepository.customer!.fitnessLevel != null) {
|
||||
if (!FitnessItem().elements.contains(customerRepository.customer!.fitnessLevel)) {
|
||||
Sport.values.forEach((element) {
|
||||
print(" .. ${element.toStr()}");
|
||||
if (element.equalsStringTo(customerRepository.customer!.fitnessLevel!)) {
|
||||
selectedSport = element;
|
||||
selectedFitnessItem = FitnessState.professional;
|
||||
}
|
||||
});
|
||||
if (selectedSport == null) {
|
||||
selectedFitnessItem = customerRepository.customer!.fitnessLevel;
|
||||
}
|
||||
} else {
|
||||
selectedFitnessItem = customerRepository.customer!.fitnessLevel;
|
||||
}
|
||||
}
|
||||
|
||||
print("selected: $selectedFitnessItem sport: $selectedSport " + customerRepository.customer!.fitnessLevel.toString());
|
||||
}
|
||||
|
||||
Sport? selectedSport;
|
||||
String? selectedFitnessItem;
|
||||
|
||||
@override
|
||||
Stream<CustomerChangeState> mapEventToState(
|
||||
CustomerChangeEvent event,
|
||||
@@ -42,7 +70,8 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
visiblePassword = !visiblePassword;
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerFitnessChange) {
|
||||
customerRepository.setFitnessLevel(event.fitness);
|
||||
//customerRepository.setFitnessLevel(event.fitness);
|
||||
selectedFitnessItem = event.fitness;
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerBirthYearChange) {
|
||||
yield CustomerChangeLoading();
|
||||
@@ -77,9 +106,25 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
} else if (event is CustomerGenderChange) {
|
||||
customerRepository.setSex(event.gender == 0 ? "m" : "w");
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerSportChange) {
|
||||
yield CustomerChangeLoading();
|
||||
selectedSport = event.sport;
|
||||
//customerRepository.setFitnessLevel(event.sport.toStr());
|
||||
yield CustomerDataChanged();
|
||||
} else if (event is CustomerSave) {
|
||||
yield CustomerSaving();
|
||||
if (validation()) {
|
||||
if (selectedFitnessItem != null) {
|
||||
if (selectedFitnessItem == FitnessState.professional) {
|
||||
if (selectedSport != null) {
|
||||
customerRepository.setFitnessLevel(selectedSport!.toStr());
|
||||
} else {
|
||||
customerRepository.setFitnessLevel(FitnessState.professional);
|
||||
}
|
||||
} else {
|
||||
customerRepository.setFitnessLevel(selectedFitnessItem!);
|
||||
}
|
||||
}
|
||||
await customerRepository.saveCustomer();
|
||||
Cache().initBadges();
|
||||
yield CustomerSaveSuccess();
|
||||
@@ -123,4 +168,7 @@ class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState>
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Sport? get getSelectedSport => this.selectedSport;
|
||||
set setSelectedSport(Sport? selectedSport) => this.selectedSport = selectedSport;
|
||||
}
|
||||
|
||||
@@ -95,6 +95,14 @@ class CustomerPasswordChange extends CustomerChangeEvent {
|
||||
List<Object> get props => [password];
|
||||
}
|
||||
|
||||
class CustomerSportChange extends CustomerChangeEvent {
|
||||
final Sport sport;
|
||||
const CustomerSportChange({required this.sport});
|
||||
|
||||
@override
|
||||
List<Object> get props => [sport];
|
||||
}
|
||||
|
||||
class CustomerChangePasswordObscure extends CustomerChangeEvent {
|
||||
const CustomerChangePasswordObscure();
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
|
||||
int step = 1;
|
||||
int countSteps = 1;
|
||||
|
||||
late double quantity;
|
||||
late double unitQuantity;
|
||||
double? quantity;
|
||||
double? unitQuantity;
|
||||
|
||||
double scrollOffset = 0;
|
||||
|
||||
@@ -38,7 +38,9 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
|
||||
required this.customerId,
|
||||
required this.workoutTree,
|
||||
required this.planBloc})
|
||||
: super(ExerciseExecutePlanAddInitial()) {
|
||||
: super(ExerciseExecutePlanAddInitial());
|
||||
|
||||
void init() {
|
||||
exerciseRepository.exerciseType = workoutTree.exerciseType;
|
||||
if (Cache().userLoggedIn!.customerId == customerId) {
|
||||
customer = Cache().userLoggedIn!;
|
||||
@@ -48,12 +50,15 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
|
||||
exercisePlanRepository.setActualPlanDetailByExerciseType(workoutTree.exerciseType!);
|
||||
exerciseRepository.customer = customer;
|
||||
countSteps = exercisePlanRepository.getActualPlanDetail()!.serie!;
|
||||
|
||||
unitQuantity = double.parse(exercisePlanRepository.getActualPlanDetail()!.weightEquation!);
|
||||
if (exercisePlanRepository.getActualPlanDetail()!.weightEquation == null) {
|
||||
unitQuantity = 0.0;
|
||||
} else {
|
||||
unitQuantity = double.parse(exercisePlanRepository.getActualPlanDetail()!.weightEquation!);
|
||||
}
|
||||
quantity = exercisePlanRepository.getActualPlanDetail()!.repeats!.toDouble();
|
||||
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
exerciseRepository.setQuantity(quantity!);
|
||||
exerciseRepository.setUnitQuantity(unitQuantity!);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -61,17 +66,18 @@ class ExerciseExecutePlanAddBloc extends Bloc<ExerciseExecutePlanAddEvent, Exerc
|
||||
try {
|
||||
if (event is ExerciseExecutePlanAddLoad) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
init();
|
||||
Track().track(TrackingEvent.my_exercise_plan_execute_open);
|
||||
yield ExerciseExecutePlanAddReady();
|
||||
} else if (event is ExerciseExecutePlanAddChangeQuantity) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
quantity = event.quantity;
|
||||
exerciseRepository.setQuantity(quantity);
|
||||
exerciseRepository.setQuantity(quantity!);
|
||||
yield ExerciseExecutePlanAddReady();
|
||||
} else if (event is ExerciseExecutePlanAddChangeUnitQuantity) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
unitQuantity = event.quantity;
|
||||
exerciseRepository.setUnitQuantity(unitQuantity);
|
||||
exerciseRepository.setUnitQuantity(unitQuantity!);
|
||||
yield ExerciseExecutePlanAddReady();
|
||||
} else if (event is ExerciseExecutePlanAddSubmit) {
|
||||
yield ExerciseExecutePlanAddLoading();
|
||||
|
||||
@@ -68,10 +68,10 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
exerciseRepository.start = DateTime.now();
|
||||
if (Cache().userLoggedIn != null) {
|
||||
customerRepository.customer = Cache().userLoggedIn!;
|
||||
weight = customerRepository.customer.getProperty("Weight");
|
||||
height = customerRepository.customer.getProperty("Height");
|
||||
birthYear = customerRepository.customer.birthYear!;
|
||||
fitnessLevel = customerRepository.customer.fitnessLevel!;
|
||||
weight = customerRepository.customer!.getProperty("Weight");
|
||||
height = customerRepository.customer!.getProperty("Height");
|
||||
birthYear = customerRepository.customer!.birthYear!;
|
||||
fitnessLevel = customerRepository.customer!.fitnessLevel!;
|
||||
}
|
||||
if (exerciseType.unit == "second") {
|
||||
stopWatchTimer.rawTime.listen((value) => {timerValue = value, this.setQuantity((value / 1000).toDouble())});
|
||||
@@ -183,22 +183,22 @@ class ExerciseNewBloc extends Bloc<ExerciseNewEvent, ExerciseNewState> with Logg
|
||||
|
||||
int year = int.parse(DateFormat(DateFormat.YEAR).format(date));
|
||||
|
||||
if (customerRepository.customer.sex == "m") {
|
||||
if (customerRepository.customer!.sex == "m") {
|
||||
//66.47 + ( 13.75 × tömeg kg-ban ) + ( 5.003 × magasság cm-ben ) − ( 6.755 × életkor évben kifejezve )
|
||||
bmr = 66.47 + (13.75 * weight) + (5.003 * height) - (6.755 * (year - customerRepository.customer.birthYear!));
|
||||
bmr = 66.47 + (13.75 * weight) + (5.003 * height) - (6.755 * (year - customerRepository.customer!.birthYear!));
|
||||
} else {
|
||||
//BMR = 655.1 + ( 9.563 × ömeg kg-ban ) + ( 1.85 × magasság cm-ben) − ( 4.676 × életkor évben kifejezve )
|
||||
bmr = 655.1 + (9.563 * weight) + (1.85 * height) - (4.676 * (year - customerRepository.customer.birthYear!));
|
||||
bmr = 655.1 + (9.563 * weight) + (1.85 * height) - (4.676 * (year - customerRepository.customer!.birthYear!));
|
||||
}
|
||||
bmrEnergy = bmr;
|
||||
|
||||
if (customerRepository.customer.fitnessLevel == FitnessState.beginner) {
|
||||
if (customerRepository.customer!.fitnessLevel == FitnessState.beginner) {
|
||||
bmr *= 1.2;
|
||||
} else if (customerRepository.customer.fitnessLevel == FitnessState.intermediate) {
|
||||
} else if (customerRepository.customer!.fitnessLevel == FitnessState.intermediate) {
|
||||
bmr *= 1.375;
|
||||
} else if (customerRepository.customer.fitnessLevel == FitnessState.advanced) {
|
||||
} else if (customerRepository.customer!.fitnessLevel == FitnessState.advanced) {
|
||||
bmr *= 1.55;
|
||||
} else if (customerRepository.customer.fitnessLevel == FitnessState.professional) {
|
||||
} else if (customerRepository.customer!.fitnessLevel == FitnessState.professional) {
|
||||
bmr *= 1.9;
|
||||
}
|
||||
return bmr;
|
||||
|
||||
@@ -75,12 +75,17 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
if (!this.dataPolicyAllowed) {
|
||||
throw Exception("Please accept our data policy");
|
||||
}
|
||||
await userRepository.addUser();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "email");
|
||||
Cache().setLoginType(LoginType.email);
|
||||
yield LoginSuccess();
|
||||
final String? validationError = validate();
|
||||
if (validationError != null) {
|
||||
yield LoginError(message: validationError);
|
||||
} else {
|
||||
await userRepository.addUser();
|
||||
accountBloc.add(AccountLogInFinished(customer: Cache().userLoggedIn!));
|
||||
await saveCustomer();
|
||||
Track().track(TrackingEvent.registration, eventValue: "email");
|
||||
Cache().setLoginType(LoginType.email);
|
||||
yield LoginSuccess();
|
||||
}
|
||||
} else if (event is RegistrationFB) {
|
||||
yield LoginLoading();
|
||||
if (!this.dataPolicyAllowed) {
|
||||
@@ -131,20 +136,36 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> with Trans {
|
||||
|
||||
Future<void> saveCustomer() async {
|
||||
customerRepository.customer = Cache().userLoggedIn!;
|
||||
customerRepository.customer.dataPolicyAllowed = 1;
|
||||
customerRepository.customer!.dataPolicyAllowed = 1;
|
||||
await customerRepository.saveCustomer();
|
||||
}
|
||||
|
||||
String? emailValidation(String email) {
|
||||
String? emailValidation(String? email) {
|
||||
String? message = Common.emailValidation(email);
|
||||
return message;
|
||||
}
|
||||
|
||||
String? passwordValidation(String value) {
|
||||
String? passwordValidation(String? value) {
|
||||
String? message = Common.passwordValidation(value);
|
||||
if (message != null) {
|
||||
message = t(message);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
String? validate() {
|
||||
String? error;
|
||||
|
||||
error = emailValidation(userRepository.user.email);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
error = passwordValidation(userRepository.user.password);
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,9 @@ class MenuBloc extends Bloc<MenuEvent, MenuState> with Trans, Logging {
|
||||
//await menuTreeRepository.createTree();
|
||||
//menuTreeRepository.getBranch(this.parent);
|
||||
//setMenuInfo();
|
||||
exerciseDeviceRepository.setDevices(Cache().getDevices()!);
|
||||
if (Cache().getDevices() != null) {
|
||||
exerciseDeviceRepository.setDevices(Cache().getDevices()!);
|
||||
}
|
||||
yield MenuReady();
|
||||
} else if (event is MenuRecreateTree) {
|
||||
yield MenuLoading();
|
||||
|
||||
@@ -25,7 +25,7 @@ class PasswordResetBloc extends Bloc<PasswordResetEvent, PasswordResetState> {
|
||||
} else if (event is PasswordResetSubmit) {
|
||||
yield PasswordResetLoading();
|
||||
await userRepository.resetPassword();
|
||||
yield PasswordResetReady();
|
||||
yield PasswordResetFinished();
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
yield PasswordResetError(message: e.toString());
|
||||
|
||||
@@ -26,3 +26,7 @@ class PasswordResetError extends PasswordResetState {
|
||||
class PasswordResetReady extends PasswordResetState {
|
||||
const PasswordResetReady();
|
||||
}
|
||||
|
||||
class PasswordResetFinished extends PasswordResetState {
|
||||
const PasswordResetFinished();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:aitrainer_app/model/result.dart';
|
||||
import 'package:aitrainer_app/repository/evaluation_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_repository.dart';
|
||||
import 'package:aitrainer_app/repository/exercise_result_repository.dart';
|
||||
import 'package:aitrainer_app/service/logging.dart';
|
||||
@@ -17,6 +18,7 @@ part 'result_state.dart';
|
||||
class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
final ExerciseResultRepository resultRepository;
|
||||
final ExerciseRepository exerciseRepository;
|
||||
final EvaluationRepository evaluationRepository = EvaluationRepository();
|
||||
final BuildContext context;
|
||||
//List<HealthDataPoint> _healthDataList = [];
|
||||
DateTime? startTime;
|
||||
@@ -53,7 +55,7 @@ class ResultBloc extends Bloc<ResultEvent, ResultState> with Logging, Trans {
|
||||
|
||||
//await _fetchHealthData();
|
||||
_matchExerciseData();
|
||||
await resultRepository.saveExerciseResults();
|
||||
//await resultRepository.saveExerciseResults();
|
||||
yield ResultReady();
|
||||
}
|
||||
} on Exception catch (ex) {
|
||||
|
||||
@@ -31,7 +31,7 @@ class TestSetControlBloc extends Bloc<TestSetControlEvent, TestSetControlState>
|
||||
}
|
||||
|
||||
void initBloc() {
|
||||
oneRepMax = executeBloc.calculate1RM(exercisePlanDetail.exercises!.last.unitQuantity, exercisePlanDetail.exercises!.last.quantity);
|
||||
oneRepMax = executeBloc.calculate1RM(exercisePlanDetail.exercises!.last.unitQuantity!, exercisePlanDetail.exercises!.last.quantity!);
|
||||
initQuantity = 12;
|
||||
quantity = initQuantity;
|
||||
initUnitQuantity = oneRepMax * 0.75;
|
||||
|
||||
@@ -136,7 +136,9 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
|
||||
if (!this.existsInPlanDetails(event.exerciseTypeId)) {
|
||||
ExercisePlanDetail exercisePlanDetail = ExercisePlanDetail(event.exerciseTypeId);
|
||||
exercisePlanDetail.exercisePlanId = exercisePlan!.exercisePlanId!;
|
||||
if (exercisePlan!.exercisePlanId != null) {
|
||||
exercisePlanDetail.exercisePlanId = exercisePlan!.exercisePlanId!;
|
||||
}
|
||||
final ExerciseType exerciseType = Cache().getExerciseTypeById(event.exerciseTypeId)!;
|
||||
|
||||
exercisePlanDetail.serie = exerciseType.unitQuantityUnit == null ? 1 : 4;
|
||||
@@ -316,8 +318,9 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
|
||||
ExercisePlanDetail? getNext() {
|
||||
ExercisePlanDetail? nextExercisePlanDetail;
|
||||
|
||||
int minStep = 99;
|
||||
if (this.exercisePlanDetails == null) {
|
||||
if (this.exercisePlanDetails != null) {
|
||||
for (final detail in this.exercisePlanDetails!) {
|
||||
if (!detail.state.equalsTo(ExercisePlanDetailState.finished)) {
|
||||
if (detail.exercises == null) {
|
||||
@@ -369,9 +372,9 @@ class TestSetExecuteBloc extends Bloc<TestSetExecuteEvent, TestSetExecuteState>
|
||||
if (!hasBegun() || exercisePlanDetail.exercises!.length < 2) {
|
||||
return text;
|
||||
}
|
||||
final double unitQuantity = exercisePlanDetail.exercises!.last.unitQuantity;
|
||||
final double quantity = exercisePlanDetail.exercises!.last.quantity;
|
||||
double oneRepMax = this.calculate1RM(quantity, unitQuantity);
|
||||
final double? unitQuantity = exercisePlanDetail.exercises!.last.unitQuantity!;
|
||||
final double? quantity = exercisePlanDetail.exercises!.last.quantity!;
|
||||
double oneRepMax = this.calculate1RM(quantity!, unitQuantity!);
|
||||
text = (oneRepMax * 0.75).round().toStringAsFixed(0) + " " + exercisePlanDetail.exerciseType!.unitQuantityUnit!;
|
||||
return text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user