callDeleteProductByIdApi method

Future<void> callDeleteProductByIdApi(
  1. String productId,
  2. ProductContentModel data
)

Implementation

Future<void> callDeleteProductByIdApi(
    String productId, ProductContentModel data) async {
  BuildContext context = Get.context!;
  Helper.progressDialog(context, "Please wait..");
  try {
    String requestTime = "";
    String responseTime = "";
    await ApiClient(
      baseUrl: ApiConstant.posBL,
      onFetchRequestTime: (time) {
        requestTime = time;
      },
      onFetchResponseTime: (time) {
        responseTime = time;
      },
      screenName: "collectStockSubmit",
      buttonName: "delete",
    )
        .deleteProductById(
      cartId: cartId,
      productId: productId,
      xRoles: SecureStorageService.readSecureData(
        SecureStorageService.xUserId,
      ),
      xUserId: SecureStorageService.readSecureData(
        SecureStorageService.xUserId,
      ),
    )
        .then((response) async {
      cart.CartModel model = response;
      if (model.status == "POS200") {
        Helper.logEvent(
          "RESPONSE_EVENT",
          success: true,
          endPoint: "${Api.addToCart}/$cartId/products/$productId",
          responseDate: responseTime,
          screenName: "collectStockSubmit",
          buttonName: "delete",
          requestDate: requestTime,
          transactionId: cartId,
        );
        // deleteProduct(data);
        cartId = model.data!.cartId!;
        discountList.value = model.data!.cartDiscountsList!;
        Helper.close();
        if (currentScan == ScanType.spotSellThru) {
          updateSpotSellThruOrder(model);
        } else if (currentScan == ScanType.sellThru) {
          updateSellThruOrder(model);
        } else if (currentScan == ScanType.collectStock) {
          totalRetailPrice = model.data!.totalRetailPrice as double;
          await updateCollectStock(model, null, null, null, data.productCode);
        }
      } else {
        Helper.close();
        if (model.errors != null) {
          Helper.messageDialog(
              Get.context!,
              model.errors![0].code ?? "Try again!!",
              model.errors![0].localeMessage ?? "Something went wrong");
        }
      }
    }).catchError((error) {
      ConditionalLogs().customLog("$error");
      Helper.close();
      MainController mainController = Get.put(MainController());
      mainController.showErrorPopup();
    });
  } catch (err, stacktrace) {
    Helper.close();
    ConditionalLogs().customLog("$err");
    ConditionalLogs().customLog("$stacktrace");
  }
}