save method

Future<void> save(
  1. Model model
)

Implementation

Future<void> save(Model model) async {
  emit(state.copyWith(isSaving: true, isError: false));
  try {
    final Json savedData = await documentProvider.saveDocument(
      model: model,
      documentId: state.data[model.idField.id].toString(),
      data: _updateCreatedAtOrUpdatedAtFields(model, _clearData(state.data, model)),
    );
    await _saveThirdTableData();
    await _upsertDynamicFieldStructures(
      documentId: state.data[model.idField.id].toString(),
      data: state.data,
      creation: false,
    );
    await _deleteDraft();
    emit(state.copyWith(
      data: savedData,
      initialData: clone(savedData),
      thirdTableData: {},
      controllerMap: _remapDocumentDataToControllerMap(model.id, savedData),
      isSaving: false,
    ));
    eventBus.send(eventId: DocumentEvent.documentChanged, request: model);
  } catch (error, stackTrace) {
    emit(state.copyWith(isSaving: false));
    throw [error, stackTrace].toHumanException('Document saving failed!');
  }
}