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.
Properties
Methods
-
errorOrNull(
) → ApiError? -
Returns the ApiError if this is a Failure, or
null. -
flatMap<
R> (Future< Result< transform(T value)) → Future<R> >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
computeon failure. -
getOrElse(
T defaultValue) → T -
Returns the success value, or
defaultValueon failure. -
getOrNull(
) → T? -
Returns the success value, or
nullon 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
transformwithout 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
actionwith the error (if any) and returnsthis. -
onSuccess(
void action(T value)) → Result< T> -
Calls
actionwith the success value (if any) and returnsthis. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited