EventualValue<T> class

EventualValue<T> wraps and manages eventual data, which can be still unresolved, have an error, or have a non-null valid value.

Use this class if you need to track eventual data, and be able to check its status explicitly from your code using hasValue, hasError and isLoading.

Implementers

Constructors

EventualValue([T initialValue])
Initializes the state with no value by default. If an argument is passed, the argument is set as the initial value.

Properties

error String
Syntactic sugar for setError(message)
write-only
errorMessage String
Returns the last error message defined
read-only
hasError bool
Returns true if an error message is currently set
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
hasValue bool
Returns true if a valid value is registered and no error has cleared it
read-only
isFresh bool
Returns true only if a valid value was set less than N seconds ago
read-only
isLoading bool
Returns true if the loading flag is currently active
read-only
isLoadingFresh bool
Returns true if setToLoading() was recently called (by default, 10 seconds). Returns false if setToLoading() was called more than X seconds ago or the value is simply not "loading".
read-only
lastError DateTime
Returns the timestamp when the last error was set
read-only
lastUpdated DateTime
Returns the last successful update
read-only
loading bool
Sets or unsets the loading flag.
write-only
loadingMessage String
Returns the optional loading message string
read / write
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
value ↔ T
Provides the current value, if there is any
read / write

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
setDefaultValue(T defaultValue) EventualValue<T>
Sets a default value only if the object has just been created and no updates have been performed on it. Use this method if you want to set a default value on an immutable EventualValue created elsewhere. This is the same as invoking final myValue = EventualValue<int>(defaultValue);. Returns this so further methods can be chained right after.
setError(String message, {bool keepPreviousValue = true}) EventualValue<T>
Sets the error message to the given value and toggles loading to false. Optionally, allows to keep the current value, even if there is an error. Returns itself so further methods can be chained right after.
setToLoading([String loadingMessage]) EventualValue<T>
Sets the loading flag to true, an optional loading message and clears the error status. Returns itself so further methods can be chained right after.
setValue(T newValue) EventualValue<T>
Sets the underlying value, clears the error status, tracks the update time and sets the loading flag to false. Returns this so further methods can be chained right after.
toString() String
A string representation of this object. [...]
override
withFreshnessTimeout(Duration duration) EventualValue<T>
By default isFresh returns false 10 seconds after the value is set. Alter the recency threshold with a new value. Returns itself so further methods can be chained right after.
withLoadingTimeout(Duration duration) EventualValue<T>
By default isLoadingFresh returns true 10 seconds after loading is set to true. This method alters the timeout threshold with a new value. Returns itself so further methods can be chained right after.

Operators

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