Skip to content

.finite()

Passes when value.isFinite is true. NaN, double.infinity and double.negativeInfinity are doubles, so they pass l.double() and l.num() unless .finite() is present. jsonDecode never produces them, but values computed in Dart can.

NumberValidator<N, O> finite({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 notFinite. Default message: value must be a finite number. value is replaced by the field name when there is one.

No annotation adds .finite() yet. Apply it to the generated schema’s field by hand if you need it, or check it in a @WithCustomValidator.

final price = l.double().finite();
price.validate(input)+1-2
  1. valid: 19.99
  2. invalid: double.nanvalue must be a finite number
  3. invalid: double.infinityvalue must be a finite number

Without .finite():

true
true