Result<T> class
Result container that wraps "value + error" into explicit success / failure semantics. Prevents using exceptions for expected failure branches.
Constructors
- Result.failure(String message, [Object? error])
-
Failed result with a human-readable
messageand optional underlyingerror.factory - Result.success(T value)
-
Successful result.
factory
Properties
- error → Object?
-
Optional underlying error object.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isFailure → bool
-
Whether this result represents failure.
no setter
- isSuccess → bool
-
Whether this result represents success.
no setter
- message → String?
-
Failure message (
nullon success).no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value → T?
-
The wrapped value (
nullon failure).no setter
Methods
-
fold<
R> (R onSuccess(T), R onFailure(String message)) → R -
Fold: invoke
onSuccesson success,onFailureon failure. -
getOrElse(
T fallback) → T -
Returns the wrapped value, or
fallbackon failure. -
getOrThrow(
) → T - Returns the wrapped value; throws StateError on failure.
-
ifFailure(
void action(String message)) → void -
Run
actionon failure. -
ifSuccess(
void action(T)) → void -
Run
actionon success. -
map<
R> (R mapper(T)) → Result< R> - Transform the value on success; stays unchanged on failure.
-
mapFailure(
String mapper(String message)) → Result< T> - Transform the failure message; stays unchanged on success.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited