save method

  1. @override
Future<ApiDocumentModel<T>> save()
override

Data stored in the model is stored in a database external to the app that is tied to the model.

The updated Resuult can be obtained at the stage where the loading is finished.

Implementation

@override
Future<ApiDocumentModel<T>> save() async {
  if (_completer != null) {
    await future;
    return this;
  }
  _completer = Completer<void>();
  try {
    await onSave();
    await saveRequest();
    notifyListeners();
    await onDidSave();
    _completer?.complete();
    _completer = null;
  } catch (e) {
    _completer?.completeError(e);
    _completer = null;
  } finally {
    _completer?.complete();
    _completer = null;
  }
  return this;
}