validator method

  1. @override
FutureOr<Result> validator(
  1. dynamic value
)
inherited

Implementation

@override
FutureOr<Result> validator(value) {
  // Short-circuit here for mid-chain nullable usage when the builder is consumed
  // directly as an IValidator and the caller invokes `validator()` (bypassing
  // the IValidator.validate() null handling logic). This happens inside some
  // composite validators (e.g. map/field validators) that call child.validator
  // for performance. Without this, a chain like `builder().string().nullable().lengthMin(2)`
  // would still run the `string()` validator on null and incorrectly fail.
  if (value == null && _nullable) {
    return Result.valid(value);
  }

  return build().validator(value);
}