Validator<T> class abstract Extensibility

Abstract base class for all validators.

A validator checks a single constraint on a value of type T and returns interpolation parameters on failure, or null on success.

class MinValidator extends Validator<int> {
  final int min;
  const MinValidator({required this.min});

  @override
  String get code => 'number.too_small';

  @override
  Map<String, dynamic>? validate(int value) =>
      value >= min ? null : {'min': min};
}

See also:

  • AsyncValidator, for a rule that has to await something.
  • VType, which accepts a validator through its add method.

Constructors

Validator()
Creates a Validator.
const

Properties

code String
The error code used for locale translation lookup.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
validate(T value) Map<String, dynamic>?
Validates value and returns interpolation parameters on failure, or null on success.

Operators

operator ==(Object other) bool
The equality operator.
inherited