not function

IValidator not(
  1. IValidator child, {
  2. String? message,
})

Passes the test if the child validator is not valid

When the inner validator succeeds, the failure will reuse its code if present, otherwise falls back to logic.not_expected. See docs/expectation_codes.md.

Usage Examples:

// Validate that a string is NOT empty
final notEmpty = not(stringEmpty());
notEmpty.validate("hello"); // Valid
notEmpty.validate("");       // Invalid

// Ensure a number is not zero
final notZero = not(isEq(0));
notZero.validate(5);  // Valid
notZero.validate(0);  // Invalid

// Validate that a field is NOT present (for optional fields)
final fieldNotPresent = not(exists());

Implementation

IValidator not(IValidator child, {String? message}) {
  return NotValidator(child, message: message);
}