Skip to content

l.int()

Passes when the value is int. Returns an IntValidator, a NumberValidator<int, int?> with .min(), .max() and .finite(). On the VM, 42.0 is a double and fails. On the web every number is a JavaScript number, so 42.0 is int is true there. For JSON that may carry either form, use l.num().

NumberValidator<int, int?> int({String? message, MessageBuilder? messageBuilder})
Parameter Type Meaning
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 invalidType. Default message: value must be an integer. value is replaced by the field name when there is one.

An int parameter maps to l.int(). @HasMin(n) and @HasMax(n) add .min(n) and .max(n); a fractional n on an int field fails generation.

final count = l.int();
count.validate(input)+1-2
  1. valid: 42
  2. invalid: 42.0value must be an integer
  3. invalid: '42'value must be an integer