PeppermintResource<T1> class
abstract
An abstraction over a resource provided by the mobile backend. Only two states are possible: success or failure. ResourceSuccess is a wrapper over the data returned by the backend. ResourceFailure is a wrapper over the exception thrown by the mobile backend.
- Implementers
- Available extensions
Constructors
Properties
- data → T1
-
Returns data.
Use getDataOrNull if you're unsure if it's a success.
Use getDataOrThrow if you need direct throw exception.
When you call this, make sure you've secured it with hasData
no setter
- error → String
-
Returns data.
Use getErrorOrNull if you're unsure if it's a success.
Use getErrorOrThrow if you need direct throw exception.
When you call this, make sure you've secured it with hasError
no setter
- hasData → bool
-
Quick helper method to check if Resource has data.
no setter
- hasError → bool
-
Quick helper method to check if Resource has error.
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
Methods
-
castFailure<
OtherType> () → PeppermintResource< OtherType> - casts a ResourceFailure to another type to overcome Dart type inference limitations.
-
getDataOrNull(
) → T1? - helper method to get the data from a Resource. returns null if the Resource is a ResourceFailure.
-
getDataOrThrow(
) → T1 - helper method to get the data from a Resource. throws ArgumentError if the Resource is a ResourceFailure.
-
getErrorOrNull(
) → String? - helper method to get an exception from a Resource. returns null if the Resource is a ResourceSuccess.
-
getErrorOrThrow(
) → String - helper method to get an exception from a Resource. throws ArgumentError if the Resource is a ResourceSuccess.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
when<
R> ({required R onSuccess(T1 data), required R onFailure(String errorMessage)}) → R -
helper method to process a resource.
onSuccess
called when the Resource is a ResourceSuccess. Exposes the wrapped data.onFailure
called when the Resource is a ResourceFailure. Exposes the wrapped Error.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited