Factory class for creating collection validation rules.
Works with List, Set, Iterable, and other collection types.
Example
final tagsValidator = Validate.all<List<String>, String>([
CollectionRules.minLength(1, error: 'At least one tag required'),
CollectionRules.maxLength(5, error: 'Maximum 5 tags'),
CollectionRules.unique(error: 'Duplicate tags not allowed'),
]);
Properties
- 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
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
all<
T, E> (bool predicate(T), {required E error}) → Rule< Iterable< T> , E> -
Validates that all items match the
predicate. -
any<
T, E> (bool predicate(T), {required E error}) → Rule< Iterable< T> , E> -
Validates that at least one item matches the
predicate. -
contains<
T, E> (T item, {required E error}) → Rule< Iterable< T> , E> -
Validates that the collection contains
item. -
lengthRange<
T, E> (int min, int max, {required E error}) → Rule< Iterable< T> , E> -
Validates that the collection length is within
minandmax(inclusive). -
maxLength<
T, E> (int max, {required E error}) → Rule< Iterable< T> , E> -
Validates that the collection has at most
maxitems. -
minLength<
T, E> (int min, {required E error}) → Rule< Iterable< T> , E> -
Validates that the collection has at least
minitems. -
none<
T, E> (bool predicate(T), {required E error}) → Rule< Iterable< T> , E> -
Validates that no items match the
predicate. -
notContains<
T, E> (T item, {required E error}) → Rule< Iterable< T> , E> -
Validates that the collection does not contain
item. -
notEmpty<
T, E> ({required E error}) → Rule< Iterable< T> , E> - Validates that the collection is not empty.
-
unique<
T, E> ({required E error}) → Rule< Iterable< T> , E> - Validates that the collection has no duplicate items.
-
uniqueBy<
T, K, E> (K selector(T), {required E error}) → Rule< Iterable< T> , E> -
Validates that the collection has no duplicate items based on
selector.