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 execute to handle or call async function

Inheritance

Constructors

FutureManager({FutureFunction<T>? futureFunction, bool reloading = true, bool reportError = true, ManagerCacheOption cacheOption = const ManagerCacheOption.non(), SuccessCallBack<T>? onSuccess, VoidCallback? onDone, ErrorCallBack? onError})
Create a FutureManager instance, You can define a futureFunction here then execute 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?
no setter
future Future<T>?
The Future that this class is doing in execute 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 execute
final
onSuccess SuccessCallBack<T>?
A function that call after execute is success and you want to manipulate data before adding it to manager
final
preReload bool
Indicate if manager is doing reloading before view state or process state is updating
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 execute 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
reportError bool
if reportError is true, every time there's an error, We will call a manager error callback
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value ↔ FutureManagerValue<T>
The current value stored in this notifier.
getter/setter pairinherited

Methods

addCustomListener(VoidCallback listener, int builderHashCode) → void
addError(Object error, {bool updateViewState = true, bool useMicrotask = false}) → void
Add error to manager, show an error widget if updateViewState is true
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
build(Widget builder(T? data)) Widget
Always display child even loading or error
canThisWidgetCallErrorListener(int hashCode) bool
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
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
eventListener(void fn(T? data)) VoidCallback
Add a listener that return a remove listener function
execute(FutureFunction<T> futureFunction, {bool? reloading, SuccessCallBack<T>? onSuccess, VoidCallback? onDone, ErrorCallBack? onError, bool throwError = false, bool useCache = true}) Future<T?>
listen({required Widget ready(T data), Widget loading = const SizedBox(), Widget error(FutureManagerError error) = EmptyErrorFunction}) Widget
Display nothing on loading and error
modifyData(FutureOr<T> onChange(T? data)) 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
removeCustomListener(VoidCallback listener, int builderHashCode) → void
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 data), void onReadyOnce(T data)?, Widget? loading, ManagerErrorBuilder? error, ManagerErrorListener? onError}) Widget
Short method for FutureManagerBuilder

Operators

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