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().
Signature
Section titled “Signature”NumberValidator<double, double?> double({String? message, MessageBuilder? messageBuilder})Parameters
Section titled “Parameters”| 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.
Code generation
Section titled “Code generation”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).
Example
Section titled “Example”final ratio = l.double();@HasMin(0) required double price, // l.double().min(0).required()required num total, // l.num().required(), accepts 1 and 1.0ratio.validate(input)+2-1- valid:
0.75 - invalid:
42 - valid:
double.nan