futurize method
Fetches data asynchronously and updates the state accordingly.
The body
function should return a Future
which resolves to the new state.
Implementation
void futurize(Future<T> Function() body,
{T? initialData, String? errorMessage, bool useEmpty = true}) {
final compute = body;
_value ??= initialData;
compute().then((newValue) {
if ((newValue == null || newValue._isEmpty()) && useEmpty) {
status = GetStatus<T>.loading();
} else {
status = GetStatus<T>.success(newValue);
}
refresh();
}, onError: (err) {
status = GetStatus.error(errorMessage ?? err.toString());
refresh();
});
}