save method

  1. @override
Future<void> 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<void> save() async {
  if (_saveCompleter != null) {
    return saving;
  }
  _saveCompleter = Completer<void>();
  await FirebaseCore.initialize();
  FirebaseCore.enqueueTransaction(() async {
    if (_saveCompleter == null) {
      return;
    }
    try {
      await onSave();
      if (_saveCompleter == null) {
        return;
      }
      await reference.set(filterOnSave(toMap(value)));
      await onDidSave();
      _saveCompleter?.complete();
      _saveCompleter = null;
    } catch (e) {
      _saveCompleter?.completeError(e);
      _saveCompleter = null;
    } finally {
      _saveCompleter?.complete();
      _saveCompleter = null;
    }
  });
  return saving;
}