prepareForCreation method
Future<void>
prepareForCreation(
- ModelId modelId
)
Implementation
Future<void> prepareForCreation(ModelId modelId) async {
this.modelId = modelId;
documentId = null;
emit(state.copyWith(isLoading: true));
emit(DocumentState.empty());
final Model? model = modelCollectionBloc.tryToFindModelById(modelId);
if (model == null) {
throw Exception('Error while loading model page with id "$modelId"');
}
final bool draftResult = await _preloadDraft(modelId);
if (draftResult) {
return;
}
final Json pageData = model.createEmptyData();
if (model.isCollection == false) {
pageData[model.idField.id] = model.id;
}
final TextControllerMap controllerMap = _mapDocumentDataToControllerMap(modelId, pageData);
emit(DocumentState.optional(
data: pageData,
initialData: clone(pageData),
controllerMap: controllerMap,
isLoading: false,
));
}