AsyncViewModelImpl<T> class abstract

Base ViewModel implementation for handling asynchronous operations with state management.

Provides a standardized way to handle loading, success, and error states for async data. Base ViewModel implementation for handling asynchronous operations with state management.

Inheritance
Annotations

Constructors

AsyncViewModelImpl(AsyncState _state, {bool loadOnInit = true})

Properties

data → T?
Get the current data (may be null if not in success state)
no setter
error Object?
Get current error if any
no setter
hasData bool
Check if the state contains valid data
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isLoading bool
Check if any operation is in progress
no setter
loadOnInit bool
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stackTrace StackTrace?
Get current stack trace if there's an error
no setter

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
cleanState() → void
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).
inherited
errorState(Object error, [StackTrace? stackTrace]) → void
Set error state
loadData() Future<T>
Override this method to provide the async data loading logic
loadingState() → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
reload() Future<void>
Public method to reload data
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
updateState(T data) → void
Update data directly
when<R>({required R initial(), required R loading(), required R success(T data), required R error(Object? err, StackTrace? stackTrace)}) → R

Operators

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