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 message and optional underlying error.
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 (null on success).
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
value → T?
The wrapped value (null on failure).
no setter

Methods

fold<R>(R onSuccess(T), R onFailure(String message)) → R
Fold: invoke onSuccess on success, onFailure on failure.
getOrElse(T fallback) → T
Returns the wrapped value, or fallback on failure.
getOrThrow() → T
Returns the wrapped value; throws StateError on failure.
ifFailure(void action(String message)) → void
Run action on failure.
ifSuccess(void action(T)) → void
Run action on 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