deleteCart method

dynamic deleteCart(
  1. BuildContext context,
  2. String cartId
)

Implementation

deleteCart(BuildContext context, String cartId) async {
  Helper.progressDialog(context, "Please wait..");
  String requestTime = DateTime.now().toString();
  try {
    // printLogs(dio);
    dio
        .delete(
      '${ApiConstant.posBaseUrl}pos-cart-service-svc/generic-carts/$cartId',
      options: Options(
        headers: {
          'X-User-Id': SecureStorageService.readSecureData(
            SecureStorageService.xUserId,
          ),
          'X-Roles': SecureStorageService.readSecureData(
            SecureStorageService.xUserId,
          ),
          'Authorization': "Bearer ${SecureStorageService.readSecureData(
            SecureStorageService.accessToken,
          )}",
        },
      ),
    )
        .then((response) {
      if (response.data != null) {
        ConditionalLogs().customLog('deleteCart${response.data}');
        CartModel model = CartModel();
        UDID.setTraceId(response.headers.map[Constants.traceIdKey]?[0] ?? "");

        Helper.logEvent(
          "RESPONSE_EVENT",
          success: true,
          endPoint: "pos-cart-service-svc/generic-carts/$cartId",
          responseDate: DateTime.now().toString(),
          screenName: "orderStock",
          requestDate: requestTime,
          transactionId: cartId,
        );
        Map<String, dynamic> creditData = response.data;
        model = CartModel.fromJson(creditData);
        if (model.status == "POS200") {
          cart_id.value = model.data!.cartId!;
          discountList.value = model.data!.cartDiscountsList!;
          updateSellThruOrder(model);
        }
      }
      Get.back();
    }).catchError((error) {
      ConditionalLogs().customLog("$error");
      Get.back();
      if (error is DioException) {
        UDID.setTraceId(
          error.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
        );
        Helper.logEvent(
          "ERROR_EVENT",
          failure: true,
          endPoint: "pos-cart-service-svc/generic-carts/$cartId",
          requestDate: requestTime,
          responseDate: DateTime.now().toString(),
          screenName: "orderStock",
          error: error,
          transactionId: cartId,
        );
      }
      MainController mainController = Get.put(MainController());
      mainController.showErrorPopup();
    });
  } catch (e) {
    Get.back();
    if (e is DioException) {
      UDID.setTraceId(
        e.response?.headers.map[Constants.traceIdKey]?[0] ?? "",
      );
      Helper.logEvent(
        "ERROR_EVENT",
        failure: true,
        endPoint: "pos-cart-service-svc/generic-carts/$cartId",
        requestDate: requestTime,
        responseDate: DateTime.now().toString(),
        screenName: "orderStock",
        error: e,
        transactionId: cartId,
      );
    }
  }
}