Finished client-side calidation

This commit is contained in:
2023-12-27 17:14:20 +03:00
parent fbdbf2545f
commit 72c0d015b3
15 changed files with 208 additions and 64 deletions

View File

@@ -83,15 +83,42 @@ class NameScreen extends StatelessWidget {
left: 16.h, right: 16.h, bottom: 50.v),
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
onPressed: () {
UserRegistrationSheet sheet =
state.nameModelObj!.userRegistrationSheet;
sheet.firstName = state.firstNameController!.text;
sheet.lastName = state.lastNameController!.text;
Navigator.pushNamed(
context,
AppRoutes.genderScreen,
arguments: sheet,
);
List<String> errors = validateFields(
state.firstNameController!.text,
state.lastNameController!.text);
if (errors.isEmpty) {
UserRegistrationSheet sheet =
state.nameModelObj!.userRegistrationSheet;
sheet.firstName = state.firstNameController!.text;
sheet.lastName = state.lastNameController!.text;
Navigator.pushNamed(
context,
AppRoutes.genderScreen,
arguments: sheet,
);
} 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'),
),
],
),
);
}
});
}),
]))));
@@ -115,4 +142,29 @@ class NameScreen extends StatelessWidget {
onTapArrowLeft(BuildContext context) {
NavigatorService.goBack();
}
List<String> validateFields(
String firstName,
String lastName,
) {
List<String> errors = [];
if (firstName.isEmpty) {
errors.add('first_name_empty'.tr);
}
if (firstName.length < 1) {
errors.add('first_name_short'.tr);
}
if (lastName.isEmpty) {
errors.add('last_name_empty'.tr);
}
if (lastName.length < 1) {
errors.add('last_name_short'.tr);
}
return errors;
}
}