Validator<T> class

A class primarily designed to retrieve validation messages based on Rules.

The Validator class takes a List of Rule. The value supplied to the Validator is supplied to the Rules in the order they were registered. The error message of the first Rule that fails is returned back. If all the Rules pass, then null is returned.

Constructors

Validator({required List<Rule<T>> rules, String entityName = 'Entity', MessageTransformer transformMessage = StringUtils.replaceWithValues})

Properties

entityName String
The name of the field that is being evaluated.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
rulesList List<Rule<T?>>
List of all registered rules.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
transformMessage MessageTransformer
A function used for transforming the message that comes back from the rules.
getter/setter pair

Methods

add(Rule<T> rule) Validator<T>
Registers a single Rule with the Validator.
addAll(List<Rule<T>> rule) Validator<T>
Registers a List of Rule with the Validator.
call(T? value) String?
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) String?
Validates and returns an error message(if any).

Operators

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