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