updateQuantity method

Future<bool> updateQuantity(
  1. BuildContext context,
  2. String quantity,
  3. String cartId,
  4. String productId,
)

Implementation

Future<bool> updateQuantity(
  BuildContext context,
  String quantity,
  String cartId,
  String productId,
) async {
  Helper.progressDialog(context, "Please wait..");
  try {
    bool status = false;
    // printLogs(dio);
    await dio
        .put(
      '${ApiConstant.posBaseUrl}pos-cart-service-svc/generic-carts/$cartId/products/$productId/quantity',
      data: json.encode({
        "quantity": quantity,
      }),
      options: Options(
        headers: {
          'X-User-Id': storage.read("XUSER_ID"),
          'X-Roles': storage.read("XUSER_ID"),
          'Accept-Language': storage.read("selected_language") ?? "en"
        },
      ),
    )
        .then((response) async {
      if (response.data != null) {
        print('updateQuantity${response.data}');
        CartModel model = CartModel();
        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!;
          await updateSellThruOrder(model);
          Get.back();
          status = true;
        } else {
          Get.back();
          Helper.messageDialog(
            Get.context!,
            model.errors?[0].code ?? "Try Again",
            model.errors?[0].localeMessage ?? "Something went wrong",
          );
        }
      } else {
        Get.back();
      }
    }).catchError((error) {
      print(error.toString());
      Get.back();
      MainController mainController = Get.put(MainController());
      mainController.showErrorPopup();
    });
    return status;
  } catch (e) {
    Get.back();
    return false;
  }
}