toDouble function
- IValidator child, {
- String? message,
Coerces a value to a double.
Handles existing doubles, integers (by converting), and strings that can be
parsed as a double.
Passes the resulting double to the child validator.
Implementation
IValidator toDouble(IValidator child, {String? message}) {
final base = ($isDouble | $isNumber | $isDoubleString) &
core.transform(
(v) => switch (v) {
final double i => i,
final int i => i.toDouble(),
final String s => double.tryParse(s.trim()),
_ => null,
},
child,
);
return handleReturnPreserveValue(base, message);
}