defaultTo function

IValidator defaultTo(
  1. dynamic defaultValue,
  2. IValidator child
)

Provides a default value if the input is null.

If the input value is null, it is replaced with defaultValue. Otherwise, the original value is passed through. Passes the resulting value to the child validator.

Implementation

IValidator defaultTo(dynamic defaultValue, IValidator child) {
  return transform((v) => v ?? defaultValue, child);
}