password static method

FormFieldValidator<String> password({
  1. String? errorMessage,
  2. int minLength = 4,
  3. int? maxLength,
  4. bool shouldContainNumber = false,
  5. bool shouldContainSpecialChars = false,
  6. bool shouldContainCapitalLetter = false,
  7. bool shouldContainSmallLetter = false,
  8. Function? reason,
  9. String onNumberNotPresent()?,
  10. String onSpecialCharsNotPresent()?,
  11. String onCapitalLetterNotPresent()?,
})

Implementation

static FormFieldValidator<String> password({
  String? errorMessage,
  int minLength = 4,
  int? maxLength,
  bool shouldContainNumber = false,
  bool shouldContainSpecialChars = false,
  bool shouldContainCapitalLetter = false,
  bool shouldContainSmallLetter = false,
  Function? reason,
  String Function()? onNumberNotPresent,
  String Function()? onSpecialCharsNotPresent,
  String Function()? onCapitalLetterNotPresent,
}) {
  return (fieldValue) {
    var mainError = errorMessage;

    if (Validator.isPassword(
      fieldValue,
      minLength: minLength,
      maxLength: maxLength,
      shouldContainSpecialChars: shouldContainSpecialChars,
      shouldContainCapitalLetter: shouldContainCapitalLetter,
      shouldContainSmallLetter: shouldContainSmallLetter,
      shouldContainNumber: shouldContainNumber,
      isNumberPresent: (present) {
        if (!present) mainError = onNumberNotPresent!();
      },
      isCapitalLetterPresent: (present) {
        if (!present) mainError = onCapitalLetterNotPresent!();
      },
      isSpecialCharsPresent: (present) {
        if (!present)
          mainError = onSpecialCharsNotPresent != null
              ? onSpecialCharsNotPresent()
              : "Password must contain special character";
      },
    )) {
      return null;
    } else {
      return mainError ?? "Password must match the required format";
    }
  };
}