load method

  1. @override
Future<ApiCollectionModel<T>> load()
override

Retrieves data and updates the data in the model.

You will be notified of model updates at the time they are retrieved.

In addition, the updated Resuult can be obtained at the stage where the loading is finished.

Implementation

@override
Future<ApiCollectionModel<T>> load() async {
  if (_completer != null) {
    await future;
    return this;
  }
  _completer = Completer<void>();
  try {
    await onLoad();
    await loadRequest();
    notifyListeners();
    await onDidLoad();
    _completer?.complete();
    _completer = null;
  } catch (e) {
    _completer?.completeError(e);
    _completer = null;
  } finally {
    _completer?.complete();
    _completer = null;
  }
  return this;
}