KResult<T> class

A simple wrapper for async operations that can be in loading, success, or error states. status: The current status of the operation (loading, success, or error). data: The data returned from a successful operation (if any). It can be null. message: An error message if the operation failed. It can be null. stackTrace: The stack trace of the error if the operation failed. It can be null.

Constructors

KResult.loading()
const

Properties

data → T?
final
hashCode int
The hash code for this object.
no setterinherited
isError bool
no setter
isLoading bool
no setter
isSuccess bool
no setter
message String
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stackTrace StackTrace?
no setter
status → _ResultStatus
final
value → T
no setter

Methods

doNext<U>(U? transform(T? data), {bool failSilently = true}) KResult<U?>
Runs transform only if this is a success. Otherwise propagates loading/error.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onError(void handler(String message, [StackTrace? st])) KResult<T>
then<U>(Future<U?> operation(T? data), {bool failSilently = true}) Future<KResult<U?>>
Runs operation only if this is a success; otherwise propagates loading/error.
toString() String
A string representation of this object.
override

Operators

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

Static Methods

error<T>(String message, [StackTrace? st, bool logError = true]) KResult<T>
success<T>(T value, {String? logMsg}) KResult<T>
tryRun<T>(T? operation(), {bool logError = true}) KResult<T?>
tryRunAsync<T>(Future<T?> operation(), {bool logError = true}) Future<KResult<T?>>
Runs operation and wraps the result in a KResult.success or KResult.error if it throws.
tryRunEither<T>(FutureOr<T?> operation(), {bool logError = true}) FutureOr<KResult<T>>