Refactor email and password validation logic in LoginForm widget

Update email and password validation logic in the LoginForm widget to only
perform validation when the state is not AuthTokenError. This ensures that
validation is skipped when there is an authentication token error.
This commit is contained in:
Mohammad Salameh
2024-04-02 18:09:23 +03:00
parent ef41940333
commit 9cc479ba17
13 changed files with 57 additions and 60 deletions
@@ -30,15 +30,17 @@ class LoginForm extends StatelessWidget {
TextFormField(
controller: AuthCubit.get(context).emailController,
validator: (value) {
if (value != null) {
if (value.isEmpty) {
return 'Please enter your email';
}
//Regex for email validation
if (!RegExp(
r'^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$')
.hasMatch(value)) {
return 'Please enter a valid email';
if (state is! AuthTokenError) {
if (value != null) {
if (value.isEmpty) {
return 'Please enter your email';
}
//Regex for email validation
if (!RegExp(
r'^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$')
.hasMatch(value)) {
return 'Please enter a valid email';
}
}
}
return null;
@@ -57,13 +59,15 @@ class LoginForm extends StatelessWidget {
TextFormField(
controller: AuthCubit.get(context).passwordController,
validator: (value) {
if (value != null) {
if (value.isNotEmpty) {
if (value.length < 6) {
return 'Password must be at least 8 characters';
if (state is! AuthTokenError) {
if (value != null) {
if (value.isNotEmpty) {
if (value.length < 6) {
return 'Password must be at least 8 characters';
}
} else {
return 'Please enter your password';
}
} else {
return 'Please enter your password';
}
}
return null;