WT1.1.2f Purchase, Product, Property, BMR, BMI, Sizes

This commit is contained in:
bossanyit
2020-11-16 15:42:40 +01:00
parent 5fa5382e3f
commit e28f1edf50
48 changed files with 2631 additions and 1441 deletions
@@ -10,29 +10,105 @@ part 'customer_change_state.dart';
class CustomerChangeBloc extends Bloc<CustomerChangeEvent, CustomerChangeState> {
final CustomerRepository customerRepository;
CustomerChangeBloc({this.customerRepository}) : super(CustomerChangeInitial());
bool visiblePassword = false;
int year = 1990;
double weight = 60;
double height = 170;
CustomerChangeBloc({this.customerRepository}) : super(CustomerChangeInitial()) {
year = this.customerRepository.customer.birthYear;
weight = this.customerRepository.getWeight();
height = this.customerRepository.getHeight();
}
@override
Stream<CustomerChangeState> mapEventToState(
CustomerChangeEvent event,
) async* {
try {
if (event is CustomerGoalChange) {
if (event is CustomerLoad) {
yield CustomerChangeLoading();
yield CustomerDataChanged();
} else if (event is CustomerGoalChange) {
customerRepository.setGoal(event.goal);
yield CustomerDataChanged();
} else if (event is CustomerChangePasswordObscure) {
visiblePassword = !visiblePassword;
yield CustomerDataChanged();
} else if (event is CustomerFitnessChange) {
customerRepository.setFitnessLevel(event.fitness);
yield CustomerDataChanged();
} else if (event is CustomerBirthYearChange) {
yield CustomerChangeLoading();
customerRepository.setBirthYear(event.year);
year = event.year;
yield CustomerDataChanged();
} else if (event is CustomerWeightChange) {
yield CustomerChangeLoading();
customerRepository.setWeight(event.weight);
weight = event.weight.toDouble();
yield CustomerDataChanged();
} else if (event is CustomerHeightChange) {
yield CustomerChangeLoading();
customerRepository.setHeight(event.height);
height = event.height.toDouble();
yield CustomerDataChanged();
} else if (event is CustomerBodyTypeChange) {
customerRepository.setBodyType(event.bodyType);
yield CustomerDataChanged();
} else if (event is CustomerEmailChange) {
customerRepository.setEmail(event.email);
yield CustomerDataChanged();
} else if (event is CustomerPasswordChange) {
customerRepository.setPassword(event.password);
yield CustomerDataChanged();
} else if (event is CustomerFirstNameChange) {
customerRepository.setFirstName(event.firstName);
yield CustomerDataChanged();
} else if (event is CustomerNameChange) {
customerRepository.setName(event.name);
yield CustomerDataChanged();
} else if (event is CustomerGenderChange) {
customerRepository.setSex(event.gender == 0 ? "m" : "w");
yield CustomerDataChanged();
} else if (event is CustomerSave) {
yield CustomerSaving();
await customerRepository.saveCustomer();
yield CustomerSaveSuccess();
if (validation()) {
await customerRepository.saveCustomer();
yield CustomerSaveSuccess();
} else {
yield CustomerSaveError(message: "Please provide the necessary information");
}
}
} on Exception catch(e) {
} on Exception catch (e) {
yield CustomerSaveError(message: e.toString());
}
}
bool validation() {
print("f " + customerRepository.customer.firstname);
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) {
bool emailValid = RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+").hasMatch(email);
return emailValid ? null : "Please type an email address";
}
String passwordValidation(String value) {
if (value == null || value.length == 0) {
return null;
}
bool valid = 8 < value.length;
return valid ? null : "Password too short";
}
String nameValidation(String value) {
if (value == null || value.length == 0) {
return "Name too short";
}
return null;
}
}
@@ -31,6 +31,78 @@ class CustomerBodyTypeChange extends CustomerChangeEvent {
List<Object> get props => [bodyType];
}
class CustomerBirthYearChange extends CustomerChangeEvent {
final int year;
const CustomerBirthYearChange({this.year});
@override
List<Object> get props => [year];
}
class CustomerWeightChange extends CustomerChangeEvent {
final int weight;
const CustomerWeightChange({this.weight});
@override
List<Object> get props => [weight];
}
class CustomerHeightChange extends CustomerChangeEvent {
final int height;
const CustomerHeightChange({this.height});
@override
List<Object> get props => [height];
}
class CustomerGenderChange extends CustomerChangeEvent {
final int gender;
const CustomerGenderChange({this.gender});
@override
List<Object> get props => [gender];
}
class CustomerEmailChange extends CustomerChangeEvent {
final String email;
const CustomerEmailChange({this.email});
@override
List<Object> get props => [email];
}
class CustomerFirstNameChange extends CustomerChangeEvent {
final String firstName;
const CustomerFirstNameChange({this.firstName});
@override
List<Object> get props => [firstName];
}
class CustomerNameChange extends CustomerChangeEvent {
final String name;
const CustomerNameChange({this.name});
@override
List<Object> get props => [name];
}
class CustomerPasswordChange extends CustomerChangeEvent {
final String password;
const CustomerPasswordChange({this.password});
@override
List<Object> get props => [password];
}
class CustomerChangePasswordObscure extends CustomerChangeEvent {
const CustomerChangePasswordObscure();
}
class CustomerLoad extends CustomerChangeEvent {
const CustomerLoad();
}
class CustomerSave extends CustomerChangeEvent {
const CustomerSave();
}
@@ -11,6 +11,10 @@ class CustomerChangeInitial extends CustomerChangeState {
const CustomerChangeInitial();
}
class CustomerChangeLoading extends CustomerChangeState {
const CustomerChangeLoading();
}
class CustomerSaving extends CustomerChangeState {
const CustomerSaving();
}