feature(registration): refactor i 2.

This commit is contained in:
mso7nueh
2024-07-14 22:16:59 +03:00
parent da447d6960
commit d49ce2120a
9 changed files with 430 additions and 357 deletions

View File

@@ -171,11 +171,11 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
});
},
children: [
LanguageSelectScreen(sheet: context.read<RegistrationCubit>().state.sheet),
CredentialsScreen(sheet: context.read<RegistrationCubit>().state.sheet),
NameScreen(),
GenderScreen(),
DateOfBirthScreen(),
LanguageSelectScreen(sheet: state.sheet),
CredentialsScreen(sheet: state.sheet),
NameScreen(sheet: state.sheet),
GenderScreen(sheet: state.sheet),
DateOfBirthScreen(sheet: state.sheet),
CityOfLivingScreen(),
BodyCircumferencesScreen(),
WeightScreen(),
@@ -197,38 +197,64 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
bool canGoNext(state) {
switch (step) {
case 2:
List<String> errors = validateFields(state.sheet.email, state.sheet.name, state.sheet.password, state.sheet.passwordConfirmation);
if (errors.isEmpty) {
return true;
} else {
String errorMessage = '';
for (var error in errors) {
errorMessage += error + '\n\n';
}
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Ошибка'),
content: Text(errorMessage),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('OK'),
),
],
),
);
return false;
}
// case 2:
// List<String> errors = validateCredentialsFields(state.sheet.email, state.sheet.name, state.sheet.password, state.sheet.passwordConfirmation);
// if (errors.isEmpty) {
// return true;
// } else {
// String errorMessage = '';
//
// for (var error in errors) {
// errorMessage += error + '\n\n';
// }
//
// showDialog(
// context: context,
// builder: (context) => AlertDialog(
// title: Text('Ошибка'),
// content: Text(errorMessage),
// actions: [
// TextButton(
// onPressed: () => Navigator.pop(context),
// child: Text('OK'),
// ),
// ],
// ),
// );
// return false;
// }
// case 3:
// List<String> errors = validateNameFields(state.sheet.firstName, state.sheet.lastName);
// if (errors.isEmpty) {
// return true;
// } else {
// String errorMessage = '';
//
// for (var error in errors) {
// errorMessage += error + '\n\n';
// }
//
// showDialog(
// context: context,
// builder: (context) => AlertDialog(
// title: Text('Ошибка'),
// content: Text(errorMessage),
// actions: [
// TextButton(
// onPressed: () => Navigator.pop(context),
// child: Text('OK'),
// ),
// ],
// ),
// );
// return false;
// }
default:
return true;
}
}
List<String> validateFields(String email, String name, String password, String passwordConfirmation) {
List<String> validateCredentialsFields(String email, String name, String password, String passwordConfirmation) {
List<String> errors = [];
if (!isEmail(email)) {
@@ -261,4 +287,26 @@ class _RegistrationScreenState extends State<RegistrationScreen> {
return errors;
}
List<String> validateNameFields(String firstName, String lastName) {
List<String> errors = [];
if (firstName.isEmpty) {
errors.add('First name cannot be empty');
}
if (firstName.length < 1) {
errors.add('First name is too short');
}
if (lastName.isEmpty) {
errors.add('Last name cannot be empty');
}
if (lastName.length < 1) {
errors.add('Last name is too short');
}
return errors;
}
}