Skip to content

l.double()

Passes when the value is double. Returns a DoubleValidator with .min(), .max() and .finite(). On the VM an int such as 42 fails, and jsonDecode produces an int for 42, so a JSON field that may arrive without a decimal point should use l.num(). NaN and infinity are doubles and pass until you add .finite().

NumberValidator<double, double?> double({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 a double. value is replaced by the field name when there is one.

A double parameter maps to l.double(), which rejects JSON integers. That is deliberate: the validator mirrors the Dart type. If your backend may send 1 for a double field, type the field as num. @HasMin(n) and @HasMax(n) add .min(n) and .max(n).

final ratio = l.double();
ratio.validate(input)+2-1
  1. valid: 0.75
  2. invalid: 42value must be a double
  3. valid: double.nan