loadPage method

Future<void> loadPage(
  1. ModelId modelId,
  2. DocumentId documentId
)

Implementation

Future<void> loadPage(ModelId modelId, DocumentId documentId) async {
  try {
    this.modelId = modelId;
    this.documentId = documentId;
    emit(state.copyWith(isLoading: true, isError: false));
    await wait(duration: const Duration(milliseconds: 50));
    final Model? model = await modelCollectionBloc.tryToFindModelByIdChecked(modelId);
    if (model == null) {
      notFoundModelError(modelId);
    }
    final bool draftResult = await _preloadDraft(modelId);
    if (draftResult) {
      return;
    }
    final Json data = await loadPageData(model: model, documentId: documentId);
    final Json dynamicStructure = await _loadDynamicStructure(model: model, documentId: documentId);
    final TextControllerMap controllerMap = _mapDocumentDataToControllerMap(modelId, data);
    data.addAll(dynamicStructure);
    emit(state.copyWith(
      data: data,
      initialData: clone(data),
      controllerMap: controllerMap,
      thirdTableData: {},
      thirdTable: {},
      isLoading: false,
    ));
  } catch (error, stackError) {
    emit(state.copyWith(isLoading: false, isError: true));
    throw [error, stackError].toHumanException('Page "$documentId" loading failed!');
  }
}