Invalid<T extends Object?> class
final
Represents a failed validation with accumulated error messages.
An Invalid contains a set of error messages describing why validation failed. When chaining validations, error messages accumulate, allowing you to collect all validation errors at once instead of failing on the first error.
The errors set automatically deduplicates messages, so identical errors from multiple failed rules won't create duplicates. This is useful when different validation rules might produce the same error message.
Construct Invalid results using Validated.invalid factory method or the check function/ValidatedOps.check extension.
Example:
// Multiple accumulated errors
final result = Validated.invalid({'Name is too short', 'Name is too long'});
// Access all errors at once for display
final errorList = result.errors.toList();
- Inheritance
- Available extensions
- Annotations
-
- @experimental
- @immutable
Properties
-
errors
→ Set<
String> -
The set of validation error messages.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- isValid → bool
-
Returns true if this is a Valid result, false if Invalid.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
and(
Validated< T> other) → Validated<T> -
Combines two validation results, merging their errors.
inherited
-
asResult(
) → Result< T, Set< String> > -
Converts this validation result to a Result type.
inherited
-
check(
bool rule(T), {required String error}) → Validated< T> -
Available on Validated<
Applies an additional validation rule to this result.T> , provided by the ValidatedOps extension -
getErrors(
) → Set< String> ? -
Gets errors if Invalid, null if Valid.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unwrapOrNull(
) → T? -
Extracts the value if Valid, or returns null if Invalid.
inherited
Operators
-
operator &(
Validated< T> other) → Validated<T> -
Combines two validation results, merging their errors.
inherited
-
operator ==(
Object other) → bool -
The equality operator.
override