Merge pull request #51 from SyncrowIOT/bugfix/SP-286

Two line error message
This commit is contained in:
Abdullah
2024-09-21 15:49:47 +03:00
committed by GitHub
2 changed files with 61 additions and 31 deletions

View File

@ -58,31 +58,39 @@ class AuthCubit extends Cubit<AuthState> {
/////////////////////////////////////VALIDATORS/////////////////////////////////////
String? passwordValidator(String? value) {
List<String> errors = [];
if (value == null || value.isEmpty) {
return "Please enter your password";
errors.add("Please enter your password");
}
if (value.length < 8) {
return 'Password must be at least 8 characters long';
if (value != null && value.length < 8) {
errors.add('Password must be at least 8 characters long');
}
if (!RegExp(r'[a-z]').hasMatch(value)) {
return 'Password must contain at least one lowercase letter';
if (value != null && !RegExp(r'[a-z]').hasMatch(value)) {
errors.add('Password must contain at least one lowercase letter');
}
if (!RegExp(r'[A-Z]').hasMatch(value)) {
return 'Password must contain at least one uppercase letter';
if (value != null && !RegExp(r'[A-Z]').hasMatch(value)) {
errors.add('Password must contain at least one uppercase letter');
}
if (!RegExp(r'\d').hasMatch(value)) {
return 'Password must contain at least one number';
if (value != null && !RegExp(r'\d').hasMatch(value)) {
errors.add('Password must contain at least one number');
}
if (!RegExp(r'[!"#$%&()*+,-./:;<=>?@[\]^_`{|}~]').hasMatch(value)) {
return 'Password must contain at least one special character';
if (value != null &&
!RegExp(r'[!"#$%&()*+,-./:;<=>?@[\]^_`{|}~]').hasMatch(value)) {
errors.add('Password must contain at least one special character');
}
return null;
if (errors.isNotEmpty) {
return errors
.join('\n'); // Join the errors with new lines to show all at once
}
return null; // No errors
}
String? fullNameValidator(String? value) {

View File

@ -105,8 +105,8 @@ class SignUpView extends StatelessWidget {
autocorrect: false,
autofillHints: const [AutofillHints.name],
// controller: AuthCubit.get(context).fullNameController,
validator: (value) =>
AuthCubit.get(context).fullNameValidator(value),
validator: (value) => AuthCubit.get(context)
.fullNameValidator(value),
onTapOutside: (event) {
FocusScope.of(context).unfocus();
},
@ -114,7 +114,11 @@ class SignUpView extends StatelessWidget {
AuthCubit.get(context).fullName = value;
},
onTap: () {},
decoration: defaultInputDecoration(context, hint: "Full Name"),
decoration: defaultInputDecoration(context,
hint: "Full Name")
.copyWith(
errorMaxLines: 2,
),
),
const SizedBox(height: 16),
const BodyMedium(
@ -129,15 +133,16 @@ class SignUpView extends StatelessWidget {
autocorrect: false,
enableSuggestions: false,
autofillHints: const [AutofillHints.email],
validator: AuthCubit.get(context).emailAddressValidator,
validator: AuthCubit.get(context)
.emailAddressValidator,
onTapOutside: (event) {
FocusScope.of(context).unfocus();
},
onChanged: (value) {
AuthCubit.get(context).email = value;
},
decoration:
defaultInputDecoration(context, hint: "Example@email.com"),
decoration: defaultInputDecoration(context,
hint: "Example@email.com"),
),
const SizedBox(height: 16),
const BodyMedium(
@ -150,17 +155,25 @@ class SignUpView extends StatelessWidget {
keyboardType: TextInputType.text,
scrollPadding: EdgeInsets.zero,
autocorrect: false,
autofillHints: const [AutofillHints.password],
validator: AuthCubit.get(context).passwordValidator,
autofillHints: const [
AutofillHints.password
],
validator: AuthCubit.get(context)
.passwordValidator,
onChanged: (value) {
AuthCubit.get(context).signUpPassword = value;
AuthCubit.get(context).signUpPassword =
value;
},
onTapOutside: (event) {
FocusScope.of(context).unfocus();
},
obscureText: !AuthCubit.get(context).isPasswordVisible,
obscureText: !AuthCubit.get(context)
.isPasswordVisible,
decoration: defaultInputDecoration(context,
hint: "At least 8 characters"),
hint: "At least 8 characters")
.copyWith(
errorMaxLines: 8,
),
),
const SizedBox(height: 16),
const BodyMedium(
@ -174,13 +187,17 @@ class SignUpView extends StatelessWidget {
scrollPadding: EdgeInsets.zero,
autocorrect: false,
enableSuggestions: false,
autofillHints: const [AutofillHints.password],
autofillHints: const [
AutofillHints.password
],
onChanged: (value) {},
validator: AuthCubit.get(context).reEnterPasswordCheck,
validator: AuthCubit.get(context)
.reEnterPasswordCheck,
onTapOutside: (event) {
FocusScope.of(context).unfocus();
},
obscureText: !AuthCubit.get(context).isPasswordVisible,
obscureText: !AuthCubit.get(context)
.isPasswordVisible,
decoration: defaultInputDecoration(context,
hint: "At least 8 characters"),
),
@ -193,10 +210,12 @@ class SignUpView extends StatelessWidget {
isDone: state is AuthLoginSuccess,
isLoading: state is AuthLoading,
customButtonStyle: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
backgroundColor:
MaterialStateProperty.all(
Colors.black.withOpacity(.25),
),
foregroundColor: MaterialStateProperty.all(
foregroundColor:
MaterialStateProperty.all(
Colors.white,
),
),
@ -204,11 +223,14 @@ class SignUpView extends StatelessWidget {
'Sign up',
),
onPressed: () {
AuthCubit.get(context).showValidationMessage = true;
if (formKey.currentState!.validate()) {
AuthCubit.get(context)
.showValidationMessage = true;
if (formKey.currentState!
.validate()) {
if ((state is! AuthLoading)) {
AuthCubit.get(context).signUp();
FocusScope.of(context).unfocus();
FocusScope.of(context)
.unfocus();
}
}
},