FutureManager<T extends Object> class

FutureManager is a wrap around Future and ChangeNotifier

FutureManager use FutureManagerBuilder instead of FutureBuilder to handle data

FutureManager provide a method asyncOperation to handle or call async function

Inheritance

Constructors

FutureManager({FutureFunction<T>? futureFunction, bool reloading = true, ManagerCacheOption cacheOption = const ManagerCacheOption.non(), SuccessCallBack<T>? onSuccess, VoidCallback? onDone, ErrorCallBack? onError})
Create a FutureManager instance, You can define a futureFunction here then asyncOperation will be call immediately

Properties

cacheOption ManagerCacheOption
An option to cache Manager's data This is not a storage cache or memory cache. Data is cache within lifetime of FutureManager only
final
data → T?
Manager's data
no setter
error FutureManagerError?
Manager's error
no setter
future Future<T>?
The Future that this class is doing in asyncOperation Sometime you want to use FutureManager class with FutureBuilder, so you can use this field
getter/setter pair
futureFunction FutureFunction<T>?
A future function that return the type of T
final
hasData bool
no setter
hasDataOrError bool
no setter
hasError bool
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
isRefreshing bool
no setter
onDone VoidCallback?
A function that call after everything is done
final
onError ErrorCallBack?
A function that call after there is an error in our asyncOperation
final
onSuccess SuccessCallBack<T>?
A function that call after asyncOperation is success and you want to manipulate data before adding it to manager
final
processingState ValueNotifier<ManagerProcessState>
Processing state of Manager. Usually useful for any lister
no setter
refresh Future<T?> Function({VoidCallback? onDone, ErrorCallBack? onError, SuccessCallBack<T>? onSuccess, bool? reloading, bool throwError, bool useCache})
refresh is a function that call asyncOperation again, but doesn't reserve configuration return null if futureFunction hasn't been initialize
getter/setter pair
reloading bool
if reloading is true, every time there's a new data, FutureManager will reset it's state to loading default value is false
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
viewState ManagerViewState
View state of Manager that control which Widget to build in FutureManagerBuilder
no setter

Methods

addError(Object error, {bool updateViewState = true, bool useMicrotask = false}) → void
Add error our current manager, reset current data if updateViewState to null
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
asyncOperation(FutureFunction<T> futureFunction, {bool? reloading, SuccessCallBack<T>? onSuccess, VoidCallback? onDone, ErrorCallBack? onError, bool throwError = false, bool useCache = true}) Future<T?>
Perform async function in manager
clearError() → void
Clear the error on this manager Only work when ViewState isn't error Best use case with Pagination when there is an error and you want to clear the error to show loading again
dispose() → void
dispose everything
listen({required Widget ready(T), Widget loading = const SizedBox(), Widget error(FutureManagerError) = EmptyErrorFunction}) Widget
Similar to when but Only listen and display data. Default to Display blank when there is loading and error But can still customize
modifyData(FutureOr<T> onChange(T?)) Future<T?>
Similar to updateData but provide current current data in Manager as param. return updated data result once completed.
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
resetData({bool updateViewState = true}) Future<void>
Reset all data and error to loading state if updateViewState is true only. if updateViewState is false, only notifyListener and update ManagerProcessState.
toString() String
A string representation of this object.
override
updateData(T? data, {bool useMicrotask = false}) → T?
Update current data in our Manager. Ignore if data is null. Use resetData instead if you want to reset to loading state
when({required Widget ready(T), Widget? loading, Widget error(FutureManagerError)?}) Widget
handle widget to show with manager state

Operators

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