Result<T, Errors extends IExpectedErrors> class
Example of usage:
AsyncResult<AuthToken, Errors2<InvalidCredentials, EmailNotConfirmed>> login(String login, String password) {
...
}
final loginResult = await login('login', 'password');
if (loginResult.hasError<InvalidCredentials>()) {
formStatus.setFailure(['Password or email are incorrect'.localize]);
return;
}
if (loginResult.hasError<EmailNotConfirmed>()) {
router.redirectToConfirmationPage();
return;
}
authStorage.storeToken(loginResult.value);
router.goToHomePage();
Constructors
-
Result.error(Iterable<
Object> errors, IExpectedErrors _expectedErrors) - Creates failed result.
- Result.success(T? _data, IExpectedErrors _expectedErrors)
- Creates successful result.
Properties
-
errors
→ Iterable<
Object> -
List of errors that happened during operation.
final
- failed → bool
-
Returns true if operation failed.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- successful → bool
-
Returns true if operation was successful.
no setter
- value → T
-
Return result of successful operation, if operation failed throws AssertionError with list of unexpected errors.
no setter
Methods
-
ensureSuccess(
) → void -
forward1<
U, E0 extends Object> ({U success(T r)?, Object failure(Object err)?}) → Result< U, Errors1< E0> > - Allows to forward and transform successful and failed results. If operation was successful, calls success callback and returns successful result with transformed data. If operation failed, calls failure callback for each error and returns failed result with transformed errors. Example:
-
forward2<
U, E0 extends Object, E1 extends Object> ({U success(T r)?, Object failure(Object err)?}) → Result< U, Errors2< E0, E1> > - Allows to forward and transform successful and failed results. If operation was successful, calls success callback and returns successful result with transformed data. If operation failed, calls failure callback for each error and returns failed result with transformed errors. Example:
-
forward3<
U, E0 extends Object, E1 extends Object, E2 extends Object> ({U success(T r)?, Object failure(Object err)?}) → Result< U, Errors3< E0, E1, E2> > - Allows to forward and transform successful and failed results. If operation was successful, calls success callback and returns successful result with transformed data. If operation failed, calls failure callback for each error and returns failed result with transformed errors.
-
forward4<
U, E0 extends Object, E1 extends Object, E2 extends Object, E3 extends Object> ({U success(T r)?, Object failure(Object err)?}) → Result< U, Errors4< E0, E1, E2, E3> > -
forward5<
U, E0 extends Object, E1 extends Object, E2 extends Object, E3 extends Object, E4 extends Object> ({U success(T r)?, Object failure(Object err)?}) → Result< U, Errors5< E0, E1, E2, E3, E4> > -
forward6<
U, E0 extends Object, E1 extends Object, E2 extends Object, E3 extends Object, E4 extends Object, E5 extends Object> ({U success(T r)?, Object failure(Object err)?}) → Result< U, Errors6< E0, E1, E2, E3, E4, E5> > -
getError<
E extends Object> () → E? - Get error of specific type, returns null if no such error.
-
getErrors<
E extends Object> () → Iterable< E> - Get all errors of specific type.
-
hasError<
E extends Object> () → bool - Check if operation failed with specific error.
-
hasSingleError<
E extends Object> () → bool - Check if there is a single error of specific type.
-
map<
U> (U f(T)) → Result< U, Errors> - Transform successful result with given function. If operation failed, returns failed result with the same errors.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited