decrementQuantity method

void decrementQuantity(
  1. String productId
)

Decrements the quantity of a cart item.

Optionally, removes the item from the cart if the quantity becomes 1.

Implementation

void decrementQuantity(String productId) {
  PersistentShoppingCartItem? item = _cartBox.get(productId);
  if (item != null) {
    if (item.quantity > 1) {
      item.decrement();
      _cartBox.put(item.key, item);
    } else {
      // Optionally, we can remove the item from the cart if the quantity is 1
      // removeProduct(productId);
    }
  }
}