StatefulData<T> class

A wrapper on data that tracks data state and notifies its listeners on changes.

It a common case when you have a data that should be loaded from some data source and you need to update your UI according to the current data state - loading, ready or error.

StatefulData is a wrapper on piece of data of specified type that handles data loading logic and notifies its listeners on data state changes. Supported data states are defined by StatefulDataState.

Typically StatefulData is used in couple with StatefulDataView widget, that automatically update the UI according to the current state of StatefulData instance.

See also:

Inheritance

Constructors

StatefulData({required Future<T?> loader(), bool isEmptyValidator(T? data) = _defaultIsEmptyValidator, bool startLoading = true})
Creates an instance of StatefulData.
StatefulData.watch({required Stream<T?> source(), bool isEmptyValidator(T? data) = _defaultIsEmptyValidator})
Creates an instance of StatefulData, that watches data changes.

Properties

data → T?
Current instance of data.
no setter
error StatefulDataError?
A last error that happened on data loading.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isEmptyValidator bool Function(T? data)
Checks if the data is empty.
getter/setter pair
isLoading bool
Indicates that data is loading.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state StatefulDataState
Current state of the data.
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
loadData() Future<void>
Loads the data.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
toString() String
A string representation of this object.
inherited

Operators

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