futurize method

void futurize(
  1. Future<T> Function() body(), {
  2. String? errorMessage,
  3. bool useEmpty = true,
})

Implementation

void futurize(Future<T> Function() body(),
    {String? errorMessage, bool useEmpty = true}) {
  final compute = body();
  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();
  });
}