max method

FormFieldValidator max (num max, { String errorText })

FormFieldValidator that requires the field's value to be less than or equal to the provided number.

Implementation

static FormFieldValidator max(
  num max, {
  String errorText,
}) {
  return (valueCandidate) {
    if (valueCandidate != null) {
      if ((valueCandidate is num && valueCandidate > max) ||
          (valueCandidate is String &&
              num.tryParse(valueCandidate) != null &&
              num.tryParse(valueCandidate) > max)) {
        return errorText ?? "Value must be less than or equal to $max";
      }
    }
    return null;
  };
}