ValidationResult<T, E> class
sealed
Immutable result of a validation operation.
Use pattern matching to handle the result:
switch (result) {
case Valid(:final value):
print('Valid: $value');
case Invalid(:final error):
print('Error: $error');
case InvalidAll(:final errors):
print('Errors: $errors');
}
Constructors
- ValidationResult.invalid(E error)
-
constfactory
-
ValidationResult.invalidAll(List<
E> errors) -
constfactory
- ValidationResult.valid(T value)
-
constfactory
Properties
- errorOrNull → E?
-
Returns the first error if invalid, or
nullif valid.no setter -
errors
→ List<
E> -
Returns all errors if invalid, or empty list if valid.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isInvalid → bool
-
Returns
trueif this result represents an invalid value.no setter - isValid → bool
-
Returns
trueif this result represents a valid value.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- valueOrNull → T?
-
Returns the value if valid, or
nullif invalid.no setter
Methods
-
fold<
R> ({required R onValid(T value), required R onInvalid(List< E> errors)}) → R -
Transforms this result by applying
onValidoronInvalid. -
map<
R> (R transform(T value)) → ValidationResult< R, E> - Maps the value if valid, returns same invalid result otherwise.
-
mapError<
E2> (E2 transform(E error)) → ValidationResult< T, E2> - Maps the error(s) if invalid, returns same valid result otherwise. Maps the error(s) if invalid, returns same valid result otherwise.
-
maybeWhen<
R> ({R valid(T value)?, R invalid(E error)?, R invalidAll(List< E> errors)?, required R orElse()}) → R - Optional pattern matching with default fallback.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
when<
R> ({required R valid(T value), required R invalid(E error), required R invalidAll(List< E> errors)}) → R - Exhaustive pattern matching.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited