itemPagePost method

Future<bool> itemPagePost({
  1. bool goBack = true,
  2. bool useValidation = true,
})

Close item page and post current (selectedItem) item to databese (server) если goBack == true (по умолчанию), после сохранения элемента, будет выполнен переход назад useValidation == true перед сохранением проводится валидация В случае успешного сохранения возвращает true

Implementation

Future<bool> itemPagePost({bool goBack = true, bool useValidation = true}) async {
  assert(selectedItem != null, 'selectedItem = null');
  if (useValidation) {
    var validationResult = selectedItem!.validateFieldValues();
    if (!validationResult.isValid) {
      var err = NsgApiException(NsgApiError(code: 999, message: validationResult.errorMessageWithFields()));
      if (NsgApiException.showExceptionDefault != null) {
        NsgApiException.showExceptionDefault!(err);
      }
      sendNotify();
      return false;
    }
  }

  currentStatus = GetStatus.loading();
  sendNotify();
  try {
    await postSelectedItem();
    var oldIndex = dataItemList.length;
    if (backupItem != null && backupItem == selectedItem && dataItemList.contains(backupItem)) {
      oldIndex = dataItemList.indexOf(backupItem!);
      dataItemList.remove(backupItem!);
    }
    if (backupItem != null) {
      backupItem = null;
    }
    if (!dataItemList.contains(selectedItem)) {
      dataItemList.insert(oldIndex, selectedItem!);
      sortDataItemList();
    }
    if (goBack) {
      Get.back();
    } else {
      saveBackup(selectedItem!);
    }
    if (masterController != null) {
      masterController!.sendNotify();
    }
  } catch (ex) {
    //если это NsgApiExceptuion, то отображаем ошибку пользователю
    if (ex is NsgApiException) {
      var func = showException ?? NsgApiException.showExceptionDefault;

      if (func != null && showExceptionDialog) func(ex);
    }
    rethrow;
  } finally {
    currentStatus = GetStatus.success(NsgBaseController.emptyData);
    sendNotify();
    selectedItemChanged.broadcast(null);
  }
  return true;
}