mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 07:49:40 +00:00
display multiple error
This commit is contained in:
@ -58,31 +58,39 @@ class AuthCubit extends Cubit<AuthState> {
|
|||||||
|
|
||||||
/////////////////////////////////////VALIDATORS/////////////////////////////////////
|
/////////////////////////////////////VALIDATORS/////////////////////////////////////
|
||||||
String? passwordValidator(String? value) {
|
String? passwordValidator(String? value) {
|
||||||
|
List<String> errors = [];
|
||||||
|
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
return "Please enter your password";
|
errors.add("Please enter your password");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value.length < 8) {
|
if (value != null && value.length < 8) {
|
||||||
return 'Password must be at least 8 characters long';
|
errors.add('Password must be at least 8 characters long');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!RegExp(r'[a-z]').hasMatch(value)) {
|
if (value != null && !RegExp(r'[a-z]').hasMatch(value)) {
|
||||||
return 'Password must contain at least one lowercase letter';
|
errors.add('Password must contain at least one lowercase letter');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!RegExp(r'[A-Z]').hasMatch(value)) {
|
if (value != null && !RegExp(r'[A-Z]').hasMatch(value)) {
|
||||||
return 'Password must contain at least one uppercase letter';
|
errors.add('Password must contain at least one uppercase letter');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!RegExp(r'\d').hasMatch(value)) {
|
if (value != null && !RegExp(r'\d').hasMatch(value)) {
|
||||||
return 'Password must contain at least one number';
|
errors.add('Password must contain at least one number');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!RegExp(r'[!"#$%&()*+,-./:;<=>?@[\]^_`{|}~]').hasMatch(value)) {
|
if (value != null &&
|
||||||
return 'Password must contain at least one special character';
|
!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) {
|
String? fullNameValidator(String? value) {
|
||||||
|
@ -105,8 +105,8 @@ class SignUpView extends StatelessWidget {
|
|||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
autofillHints: const [AutofillHints.name],
|
autofillHints: const [AutofillHints.name],
|
||||||
// controller: AuthCubit.get(context).fullNameController,
|
// controller: AuthCubit.get(context).fullNameController,
|
||||||
validator: (value) =>
|
validator: (value) => AuthCubit.get(context)
|
||||||
AuthCubit.get(context).fullNameValidator(value),
|
.fullNameValidator(value),
|
||||||
onTapOutside: (event) {
|
onTapOutside: (event) {
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
},
|
},
|
||||||
@ -114,7 +114,11 @@ class SignUpView extends StatelessWidget {
|
|||||||
AuthCubit.get(context).fullName = value;
|
AuthCubit.get(context).fullName = value;
|
||||||
},
|
},
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
decoration: defaultInputDecoration(context, hint: "Full Name"),
|
decoration: defaultInputDecoration(context,
|
||||||
|
hint: "Full Name")
|
||||||
|
.copyWith(
|
||||||
|
errorMaxLines: 2,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const BodyMedium(
|
const BodyMedium(
|
||||||
@ -129,15 +133,16 @@ class SignUpView extends StatelessWidget {
|
|||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
enableSuggestions: false,
|
enableSuggestions: false,
|
||||||
autofillHints: const [AutofillHints.email],
|
autofillHints: const [AutofillHints.email],
|
||||||
validator: AuthCubit.get(context).emailAddressValidator,
|
validator: AuthCubit.get(context)
|
||||||
|
.emailAddressValidator,
|
||||||
onTapOutside: (event) {
|
onTapOutside: (event) {
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
},
|
},
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
AuthCubit.get(context).email = value;
|
AuthCubit.get(context).email = value;
|
||||||
},
|
},
|
||||||
decoration:
|
decoration: defaultInputDecoration(context,
|
||||||
defaultInputDecoration(context, hint: "Example@email.com"),
|
hint: "Example@email.com"),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const BodyMedium(
|
const BodyMedium(
|
||||||
@ -150,19 +155,25 @@ class SignUpView extends StatelessWidget {
|
|||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
scrollPadding: EdgeInsets.zero,
|
scrollPadding: EdgeInsets.zero,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
autofillHints: const [AutofillHints.password],
|
autofillHints: const [
|
||||||
validator: AuthCubit.get(context).passwordValidator,
|
AutofillHints.password
|
||||||
|
],
|
||||||
|
validator: AuthCubit.get(context)
|
||||||
|
.passwordValidator,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
AuthCubit.get(context).signUpPassword = value;
|
AuthCubit.get(context).signUpPassword =
|
||||||
|
value;
|
||||||
},
|
},
|
||||||
onTapOutside: (event) {
|
onTapOutside: (event) {
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
},
|
},
|
||||||
obscureText: !AuthCubit.get(context).isPasswordVisible,
|
obscureText: !AuthCubit.get(context)
|
||||||
|
.isPasswordVisible,
|
||||||
decoration: defaultInputDecoration(context,
|
decoration: defaultInputDecoration(context,
|
||||||
hint: "At least 8 characters").copyWith(
|
hint: "At least 8 characters")
|
||||||
errorMaxLines: 2,
|
.copyWith(
|
||||||
),
|
errorMaxLines: 8,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const BodyMedium(
|
const BodyMedium(
|
||||||
@ -176,13 +187,17 @@ class SignUpView extends StatelessWidget {
|
|||||||
scrollPadding: EdgeInsets.zero,
|
scrollPadding: EdgeInsets.zero,
|
||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
enableSuggestions: false,
|
enableSuggestions: false,
|
||||||
autofillHints: const [AutofillHints.password],
|
autofillHints: const [
|
||||||
|
AutofillHints.password
|
||||||
|
],
|
||||||
onChanged: (value) {},
|
onChanged: (value) {},
|
||||||
validator: AuthCubit.get(context).reEnterPasswordCheck,
|
validator: AuthCubit.get(context)
|
||||||
|
.reEnterPasswordCheck,
|
||||||
onTapOutside: (event) {
|
onTapOutside: (event) {
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
},
|
},
|
||||||
obscureText: !AuthCubit.get(context).isPasswordVisible,
|
obscureText: !AuthCubit.get(context)
|
||||||
|
.isPasswordVisible,
|
||||||
decoration: defaultInputDecoration(context,
|
decoration: defaultInputDecoration(context,
|
||||||
hint: "At least 8 characters"),
|
hint: "At least 8 characters"),
|
||||||
),
|
),
|
||||||
@ -195,10 +210,12 @@ class SignUpView extends StatelessWidget {
|
|||||||
isDone: state is AuthLoginSuccess,
|
isDone: state is AuthLoginSuccess,
|
||||||
isLoading: state is AuthLoading,
|
isLoading: state is AuthLoading,
|
||||||
customButtonStyle: ButtonStyle(
|
customButtonStyle: ButtonStyle(
|
||||||
backgroundColor: MaterialStateProperty.all(
|
backgroundColor:
|
||||||
|
MaterialStateProperty.all(
|
||||||
Colors.black.withOpacity(.25),
|
Colors.black.withOpacity(.25),
|
||||||
),
|
),
|
||||||
foregroundColor: MaterialStateProperty.all(
|
foregroundColor:
|
||||||
|
MaterialStateProperty.all(
|
||||||
Colors.white,
|
Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -206,11 +223,14 @@ class SignUpView extends StatelessWidget {
|
|||||||
'Sign up',
|
'Sign up',
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
AuthCubit.get(context).showValidationMessage = true;
|
AuthCubit.get(context)
|
||||||
if (formKey.currentState!.validate()) {
|
.showValidationMessage = true;
|
||||||
|
if (formKey.currentState!
|
||||||
|
.validate()) {
|
||||||
if ((state is! AuthLoading)) {
|
if ((state is! AuthLoading)) {
|
||||||
AuthCubit.get(context).signUp();
|
AuthCubit.get(context).signUp();
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context)
|
||||||
|
.unfocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user