Result<T> class sealed

A value that is either a Success<T> or a Failure<T>.

Use fold for exhaustive handling, map / flatMap for chaining, and getOrNull / getOrElse for quick extraction.

Implementers

Properties

hashCode int
The hash code for this object.
no setterinherited
isFailure bool
no setter
isSuccess bool
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

errorOrNull() ApiError?
Returns the ApiError if this is a Failure, or null.
flatMap<R>(Future<Result<R>> transform(T value)) Future<Result<R>>
Chains another Result-returning operation on success. If this is a Failure, it is returned unchanged.
fold<R>({required R onSuccess(T value), required R onFailure(ApiError error)}) → R
Handles both cases and returns R.
getOrCompute(T compute(ApiError error)) → T
Returns the success value, or the result of calling compute on failure.
getOrElse(T defaultValue) → T
Returns the success value, or defaultValue on failure.
getOrNull() → T?
Returns the success value, or null on failure.
getOrThrow() → T
Throws the underlying ApiError if this is a Failure. Use sparingly — prefer fold for normal control flow.
map<R>(R transform(T value)) Result<R>
Transforms the success value with transform. If this is a Failure, it is returned unchanged.
mapError(ApiError transform(ApiError error)) Result<T>
Transforms the error with transform without changing the value type.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onFailure(void action(ApiError error)) Result<T>
Calls action with the error (if any) and returns this.
onSuccess(void action(T value)) Result<T>
Calls action with the success value (if any) and returns this.
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

guard<T>(T compute()) Result<T>
Wraps a synchronous computation, catching any exception as Failure.
guardAsync<T>(Future<T> compute()) Future<Result<T>>
Wraps an async computation, catching any exception as Failure.