callEngineImpl method

Future<void> callEngineImpl({
  1. required String localFilePath,
  2. required String serverFilePath,
  3. double? timeAppUpload,
})

Implementation

Future<void> callEngineImpl({
  required String localFilePath,
  required String serverFilePath,
  double? timeAppUpload,
}) async {
  var callEngineRes = await callEngineUsecase(
    claimId: argument!.claimId,
    imageName: basename(localFilePath),
    filePath: serverFilePath,
    position: positionIds[currentTabIndex.value],
    direction: argument!.carPartDirectionEnum.excelId,
    vehiclePartExcelId: currentTabIndex.value == 2
        ? carPartOnSelected.value?.vehiclePartExcelId ?? ''
        : '',
    timeAppUpload: timeAppUpload,
    utcTimeCreated: createdDateTime,
    uploadLocation: currentLocation,
    locationName: imageLocation,
    oldImageId: currentReplacedImageId.value.isNotEmpty
        ? currentReplacedImageId.value
        : null,
    isTruck: argument?.carModelEnum == CarModelEnum.truck,
  );

  callEngineRes.fold(
    (l) {
      isLoading(false);

      /// Code from engine
      if (l.errorCodeFromEngine != null) {
        status(
          BaseStatus(
            message: '${l.code.toString()}: ${l.details.toString()}',
            state: AppState.customError,
          ),
        );
        showErrorDialog(true);
        status(
          BaseStatus(
            message: '${l.code.toString()}: ${l.details.toString()}',
            state: AppState.customError,
          ),
        );
        showRetake(false);
        showErrorDialog(true);
      } else {
        status(
          BaseStatus(
            message: '${l.code.toString()}: ${l.details.toString()}',
            state: AppState.customError,
          ),
        );
        showErrorDialog(true);
        showRetake(true);
      }
    },
    (r) async {
      await getCarPartsForCloseUpShot();
      isLoading(false);
      if (currentTabIndex.value == 2) {
        updateDirection(r);
        previewFile.value = null;
        cameraController?.resumePreview();
      } else if (r.errorCodeFromEngine == null ||
          r.errorCodeFromEngine == 0) {
        updateDirection(r);
        status(BaseStatus(message: null, state: AppState.success));
        damageAssessmentResponse.value = r;
        showRetake(false);
      } else {
        cacheDamageResponse = r;

        /// confident level thấp
        if (warningCodeFromEngine.contains(r.errorCodeFromEngine)) {
          status(BaseStatus(message: r.message, state: AppState.warning));
          showRetake(false);
          isConfidentLevelWarning(true);
        } else {
          status(BaseStatus(message: r.message, state: AppState.customError));
          showRetake(false);
          showErrorDialog(true);
        }
      }
    },
  );
}