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

Constructors

Error(Failure failure)
Creates an Error holding failure.
const

Properties

dataOrNull → T?

Available on Result<T>, provided by the ResultX extension

The wrapped data, or null if this is an Error.
no setter
errorOrNull Failure?

Available on Result<T>, provided by the ResultX extension

The wrapped failure, or null if 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<T>, provided by the ResultX extension

Whether this result is an Error.
no setter
isSuccess bool

Available on Result<T>, provided by the ResultX extension

Whether this result is a Success.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

asyncFlatMap<R>(Future<Result<R>> transform(T data)) Future<Result<R>>

Available on Result<T>, provided by the ResultAsyncX extension

Like asyncMap but transform returns its own Result, allowing async failures to short-circuit without nesting Future<Result<Result<R>>>.
asyncMap<R>(Future<R> transform(T data)) Future<Result<R>>

Available on Result<T>, provided by the ResultAsyncX extension

If this is a Success, awaits transform applied 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<T>, provided by the ResultX extension

If this is a Success and predicate returns false for its data, converts it into an Error using onUnmet. 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<T>, provided by the ResultX extension

Returns the wrapped failure on error, or throws a StateError on success. Symmetric counterpart to getOrThrow.
filter(bool test(T item)) Result<List<T>>

Available on Result<List<T>>, provided by the ResultListX extension

Keeps only the elements satisfying test. Errors pass through unchanged.
firstOrError({String emptyMessage = 'List is empty'}) Result<T>

Available on Result<List<T>>, provided by the ResultListX extension

Returns the first element of the wrapped list as a Result<T>. If the list is empty, the result becomes an Error carrying Failure.notFound with emptyMessage.
flatMap<R>(Result<R> transform(T data)) Result<R>
Like map but the transform returns its own Result, allowing failures to short-circuit without nesting Result<Result<R>>.
override
flatten() Result<T>

Available on Result<Result<T>>, provided by the FlattenResultX extension

Removes one layer of nesting from Result<Result<T>> to Result<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<T>, provided by the ResultX extension

Returns the data on success, or defaultValue on failure.
getOrThrow() → T

Available on Result<T>, provided by the ResultX extension

Returns the data on success, or throws a ResultUnwrapException on failure.
map<R>(R transform(T data)) Result<R>
If this is a Success, applies transform to 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 transform to 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<List<T>>, provided by the ResultListX extension

Transforms each element of the wrapped list with transform.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onComplete(void action()) Result<T>

Available on Result<T>, provided by the ResultX extension

Invokes action regardless of variant — a finally-style hook for cleanup like dismissing a spinner. Returns this for chaining.
onError(void action(Failure failure)) Result<T>

Available on Result<T>, provided by the ResultX extension

Invokes action with the failure if this is an Error. Returns this for chaining.
onSuccess(void action(T data)) Result<T>

Available on Result<T>, provided by the ResultX extension

Invokes action with the data if this is a Success. Returns this for chaining.
recover(T recovery(Failure failure)) Result<T>

Available on Result<T>, provided by the ResultX extension

Synchronous counterpart to FutureResultX.recover. If this is an Error, substitutes a default success value computed from the failure; otherwise propagates the Success unchanged.
recoverWith(Result<T> recovery(Failure failure)) Result<T>

Available on Result<T>, provided by the ResultX extension

Synchronous counterpart to FutureResultX.recoverWith. If this is an Error, delegates to recovery for a replacement Result; otherwise propagates the Success unchanged.
tap(void action(T data)) Result<T>

Available on Result<T>, provided by the ResultX extension

Invokes action with 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 success or error and returning the produced value.
override
whereResult(bool test(T item)) Result<List<T>>

Available on Result<List<T>>, provided by the ResultListX extension

Alias for filter that reads more naturally next to mapList.

Operators

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