Skip to content

.max()

Passes when the value is at most maxValue. The limit has the validator’s number type.

NumberValidator<N, O> max(N maxValue, {String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
maxValue N The largest accepted value, inclusive. params['max'].
message String? Replaces the default error message.
messageBuilder MessageBuilder? Builds the message from the issue. message wins when both are given. See Message builders.

Code tooBig. Default message: value must be less than or equal to 100. value is replaced by the field name when there is one.

@HasMax(n) on an int, double or num field, with the same rules as @HasMin.

final age = l.int().max(100);
age.validate(input)+1-1
  1. valid: 100
  2. invalid: 101value must be less than or equal to 100
final ratio = l.double().max(1.5);
ratio.validate(input)+1-1
  1. valid: 1.5
  2. invalid: 2.0value must be less than or equal to 1.5