maxLength<T> static method

FormFieldValidator<T> maxLength<T>(
  1. int maxLength, {
  2. String? errorText,
})

Implementation

static FormFieldValidator<T> maxLength<T>(int maxLength, {String? errorText}) {
  assert(maxLength > 0);
  return (T? valueCandidate) {
    assert(valueCandidate is String || valueCandidate is Iterable || valueCandidate == null);
    int valueLength = 0;
    if (valueCandidate is String) valueLength = valueCandidate.length;
    if (valueCandidate is Iterable) valueLength = valueCandidate.length;
    return null != valueCandidate && valueLength > maxLength
        ? errorText ?? BasicFormValidatorMessageError().maxLength!(maxLength)
        : null;
  };
}