Error<T> class
final
The failed variant of a Result.
Note: this class shadows dart:core.Error. See the Result doc for the
hide Error workaround.
- Inheritance
- Available extensions
Properties
- dataOrNull → T?
-
Available on Result<
The wrapped data, orT> , provided by the ResultX extensionnullif this is an Error.no setter - errorOrNull → Failure?
-
Available on Result<
The wrapped failure, orT> , provided by the ResultX extensionnullif this is a Success.no setter - failure → Failure
-
The structured description of why the operation failed.
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- isError → bool
-
Available on Result<
Whether this result is an Error.T> , provided by the ResultX extensionno setter - isSuccess → bool
-
Available on Result<
Whether this result is a Success.T> , provided by the ResultX extensionno setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
asyncFlatMap<
R> (Future< Result< transform(T data)) → Future<R> >Result< R> > -
Available on Result<
Like asyncMap butT> , provided by the ResultAsyncX extensiontransformreturns its own Result, allowing async failures to short-circuit without nestingFuture<Result<Result<R>>>. -
asyncMap<
R> (Future< R> transform(T data)) → Future<Result< R> > -
Available on Result<
If this is a Success, awaitsT> , provided by the ResultAsyncX extensiontransformapplied to the data and wraps the return value in a new Success. Otherwise resolves immediately with the existing Error. -
ensure(
bool predicate(T data), Failure onUnmet(T data)) → Result< T> -
Available on Result<
If this is a Success andT> , provided by the ResultX extensionpredicatereturnsfalsefor its data, converts it into an Error usingonUnmet. Otherwise propagates the result unchanged. Handy for post-success domain validation, e.g. an HTTP 200 envelope whose body still indicates a logical failure. -
errorOrThrow(
) → Failure -
Available on Result<
Returns the wrapped failure on error, or throws a StateError on success. Symmetric counterpart to getOrThrow.T> , provided by the ResultX extension -
filter(
bool test(T item)) → Result< List< T> > -
Available on Result<
Keeps only the elements satisfyingList< , provided by the ResultListX extensionT> >test. Errors pass through unchanged. -
firstOrError(
{String emptyMessage = 'List is empty'}) → Result< T> -
Available on Result<
Returns the first element of the wrapped list as aList< , provided by the ResultListX extensionT> >Result<T>. If the list is empty, the result becomes an Error carrying Failure.notFound withemptyMessage. -
flatMap<
R> (Result< R> transform(T data)) → Result<R> -
Like map but the
transformreturns its own Result, allowing failures to short-circuit without nestingResult<Result<R>>.override -
flatten(
) → Result< T> -
Available on Result<
Removes one layer of nesting fromResult< , provided by the FlattenResultX extensionT> >Result<Result<T>>toResult<T>. -
fold<
R> (R onSuccess(T data), R onError(Failure failure)) → R -
Alias for when with positional callbacks, matching the Either/Result
convention used in functional libraries.
override
-
getOrElse(
T defaultValue) → T -
Available on Result<
Returns the data on success, orT> , provided by the ResultX extensiondefaultValueon failure. -
getOrThrow(
) → T -
Available on Result<
Returns the data on success, or throws a ResultUnwrapException on failure.T> , provided by the ResultX extension -
map<
R> (R transform(T data)) → Result< R> -
If this is a Success, applies
transformto the data and wraps the outcome in a new Success. Otherwise propagates the Error unchanged.override -
mapError(
Failure transform(Failure failure)) → Result< T> -
If this is an Error, applies
transformto the failure and wraps the outcome in a new Error. Otherwise propagates the Success unchanged.override -
mapList<
R> (R transform(T item)) → Result< List< R> > -
Available on Result<
Transforms each element of the wrapped list withList< , provided by the ResultListX extensionT> >transform. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onComplete(
void action()) → Result< T> -
Available on Result<
InvokesT> , provided by the ResultX extensionactionregardless of variant — a finally-style hook for cleanup like dismissing a spinner. Returnsthisfor chaining. -
onError(
void action(Failure failure)) → Result< T> -
Available on Result<
InvokesT> , provided by the ResultX extensionactionwith the failure if this is an Error. Returnsthisfor chaining. -
onSuccess(
void action(T data)) → Result< T> -
Available on Result<
InvokesT> , provided by the ResultX extensionactionwith the data if this is a Success. Returnsthisfor chaining. -
recover(
T recovery(Failure failure)) → Result< T> -
Available on Result<
Synchronous counterpart to FutureResultX.recover. If this is an Error, substitutes a default success value computed from the failure; otherwise propagates the Success unchanged.T> , provided by the ResultX extension -
recoverWith(
Result< T> recovery(Failure failure)) → Result<T> -
Available on Result<
Synchronous counterpart to FutureResultX.recoverWith. If this is an Error, delegates toT> , provided by the ResultX extensionrecoveryfor a replacement Result; otherwise propagates the Success unchanged. -
tap(
void action(T data)) → Result< T> -
Available on Result<
InvokesT> , provided by the ResultX extensionactionwith the data on success, passing through the result unchanged. Useful for side effects like logging without transforming. -
toString(
) → String -
A string representation of this object.
override
-
when<
R> ({required R success(T data), required R error(Failure failure)}) → R -
Pattern-matches on the variant, calling
successorerrorand returning the produced value.override -
whereResult(
bool test(T item)) → Result< List< T> > -
Available on Result<
Alias for filter that reads more naturally next to mapList.List< , provided by the ResultListX extensionT> >
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override