Result<T> class sealed

A class representing the result of an operation that can either succeed or fail.

Implementers

Constructors

Result.failure(ErrorMessage error)
Factory for creating a Result instance representing a failure.
factory
Result.from(T getter(), {ExceptionHandler? exceptionHandler, String? errorGroup})
A factory constructor to create a Result instance from a function that might throw an exception. The ExceptionHandler can be provided to handle exceptions and return an ErrorMessage. The errorGroup can be used to categorize the type of error.
factory
Result.success(T value)
Factory for creating a Result instance representing a success.
factory

Properties

error ErrorMessage?
An error message in case the result represents a failure.
no setter
hashCode int
The hash code for this object.
no setterinherited
isSuccess bool
A getter that returns true if the operation was successful (i.e., no error).
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value → T
A getter that returns the value if the operation was successful, or throws a ResultException if it wasn't.
no setter
valueOrNull → T?
A getter that returns the value if the operation was successful, or null if it wasn't.
no setter

Methods

flatMap<R>(R onSuccess(T value), {ExceptionHandler? exceptionHandler, String? errorGroup}) Result<R>
Maps a Result<T> to Result<R> using the provided function. If the original result is a failure, the same error is retained.
flatMapAsync<R>(Future<R> onSuccess(T value), {ExceptionHandler? exceptionHandler, String? errorGroup}) FutureOr<Result<R>>
Similar to flatMap, but for asynchronous operations. Maps a Result<T> to FutureOr<Result<R>>.
fold<R>(R onSuccess(T value), {required R onFailure(ErrorMessage errorMessage)}) → R
Allows handling the success and failure cases of a Result separately and returns a value of type R.
foldNotNull<R>(R onSuccess(T value), {required R onFailure(ErrorMessage errorMessage)}) → R?
Similar to fold, but ensures that the value is not null before calling onSuccess.
map({required void onSuccess(T value), required void onFailure(ErrorMessage errorMessage)}) → void
Calls the appropriate callback based on the result being a success or a failure.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onFailure(void callback(ErrorMessage errorMessage)) → void
Calls the provided callback if the result is a failure.
onSuccess(void callback(T value)) → void
Calls the provided callback if the result is a success.
recover(T onRecover(ErrorMessage errorMessage)) Success<T>
Recovers from a failure by providing a new value.
toString() String
A string representation of this object.
override

Operators

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

Static Methods

fromAsync<T>(Future<T> getter(), {ExceptionHandler? exceptionHandler, String? errorGroup}) Future<Result<T>>
A static method to create a Result instance from an async function that might throw an exception. The ExceptionHandler can be provided to handle exceptions and return an ErrorMessage. The errorGroup can be used to categorize the type of error.