validate method

  1. @override
List<String>? validate(
  1. String? value
)
override

Implementation

@override
List<String>? validate(String? value) {
  if (value == null) return null;

  final errors = List<String>.empty(growable: true);

  if (value.length < minLength)
    errors.add(ValidationErrorsLocalized.MIN_LENGTH
        .replaceAll("{{0}}", minLength.toString()));
  if (value.length > maxLength)
    errors.add(ValidationErrorsLocalized.MAX_LENGTH
        .replaceAll("{{0}}", maxLength.toString()));

  if (errors.isEmpty) return null;

  return errors;
}