ErrorOr<TValue> class

Represents a value that can either be an error or a valid value of type TValue.

Constructors

ErrorOr.fromError(Errors error)
Constructs an ErrorOr instance representing an error with the given error.
ErrorOr.fromErrors(List<Errors> errors)
Constructs an ErrorOr instance representing an error with the given list of errors.
ErrorOr.fromValue(TValue value)
Constructs an ErrorOr instance representing a value with the given value.

Properties

errors List<Errors>
Returns a list of errors if the instance represents an error; otherwise, returns a list containing noErrors.
no setter
errorsOrEmptyList List<Errors>
Returns a list of errors if the instance represents an error; otherwise, returns an empty list.
no setter
firstError Errors
Returns the first error if the instance represents an error; otherwise, returns noFirstError.
no setter
hashCode int
The hash code for this object.
no setterinherited
isError bool
Indicates whether the current instance represents an error.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value → TValue
Returns the value if the instance represents a value; otherwise, throws an exception.
no setter
valueOrNull → TValue?
Returns the value if the ErrorOr is not an error, otherwise returns null.
no setter

Methods

also<TNextValue>(ErrorOr<TNextValue> onValue(TValue value)) ErrorOr<TNextValue>
Represents a computation that may either produce a value of type TValue or an error. Chains a computation to be executed if this ErrorOr contains a value.
alsoAsync<TNextValue>(Future<ErrorOr<TNextValue>> onValue(TValue value)) Future<ErrorOr<TNextValue>>
A helper method that allows chaining asynchronous operations on a ErrorOr instance.
alsoDo(dynamic onValue(TValue value)) ErrorOr<TValue>
Executes the provided function onValue if the ErrorOr instance is not an error. The onValue function takes a single argument of type TValue and returns no value. Returns the current ErrorOr instance.
alsoDoAsync(Future onValue(TValue value)) Future<ErrorOr<TValue>>
A helper method that allows chaining asynchronous operations on a ErrorOr object.
doSwitch(dynamic onValue(TValue value), dynamic onError(List<Errors> errors)) → void
Performs a switch operation based on the state of the ErrorOr object.
doSwitchAsync(Future onValue(TValue value), Future onError(List<Errors> errors)) Future
Performs a switch operation asynchronously based on the state of the ErrorOr object.
doSwitchFirst(dynamic onValue(TValue value), dynamic onFirstError(Errors error)) → dynamic
Performs a switch operation on the ErrorOr object.
doSwitchFirstAsync(Future onValue(TValue value), Future onFirstError(Errors error)) Future
Performs a switch operation based on the state of the ErrorOr object.
failIf(bool onValue(TValue value), Errors error) ErrorOr<TValue>
A class representing a result that can either be an error or a value. Returns a new ErrorOr instance with the specified onValue and error.
failIfAsync(Future<bool> onValue(TValue value), Errors error) Future<ErrorOr<TValue>>
A method that checks if the current ErrorOr instance is not an error and evaluates a given condition asynchronously. If the condition is true, it returns an ErrorOr instance created from the provided Errors object. Otherwise, it returns the current ErrorOr instance.
match<TNextValue>(TNextValue onValue(TValue value), TNextValue onError(List<Errors> errors)) → TNextValue
Matches the value of the ErrorOr instance and returns a result based on whether it is an error or a value.
matchAsync<TNextValue>(Future<TNextValue> onValue(TValue value), Future<TNextValue> onError(List<Errors> errors)) Future<TNextValue>
Matches the value or errors of the ErrorOr instance and returns a future result.
matchFirst<TNextValue>(TNextValue onValue(TValue value), TNextValue onError(Errors error)) → TNextValue
Matches the value of the ErrorOr instance and returns the result of the matching function.
matchFirstAsync<TNextValue>(Future<TNextValue> onValue(TValue value), Future<TNextValue> onError(Errors error)) Future<TNextValue>
Matches the value or error of the ErrorOr instance and returns a future result.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
orElse({Errors errorOnErrorHandler(List<Errors> errors)?, List<Errors> errorsOnErrorHandler(List<Errors> errors)?, TValue? valueOnErrorHandler(List<Errors> errors)?, TValue? valueOnError, Errors? errorOnError}) ErrorOr<TValue>
orElseAsync({Future<Errors> errorOnErrorHandler(List<Errors> errors)?, Future<List<Errors>> errorsOnErrorHandler(List<Errors> errors)?, Future<TValue?> valueOnErrorHandler(List<Errors> errors)?, Future<TValue?>? valueOnError, Future<Errors>? errorOnError}) Future<ErrorOr<TValue>>
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

noErrors Errors
A static instance of Errors.unexpected representing the absence of any errors.
final
noFirstError Errors
A static field representing an unexpected error when trying to retrieve the first error from a successful ErrorOr.
final