updateQuantity method

void updateQuantity(
  1. String productId,
  2. List<ProductVariant> variants,
  3. int newQuantity
)

updateQuantity is used to increment/decrement the item quantity Example: void updateQuantity(CartModel item, int newQuantity) { flutterCart.updateQuantity( item.productId, item.variants, newQuantity); }

Implementation

void updateQuantity(
    String productId, List<ProductVariant> variants, int newQuantity) {
  if (newQuantity == 0) {
    removeItem(productId, variants);
  } else {
    var itemIndex = _cartItemsList.indexWhere((item) =>
        item.productId == productId &&
        _areVariantsEqual(item.variants, variants));

    if (itemIndex != -1) {
      _cartItemsList[itemIndex] =
          _cartItemsList[itemIndex].copyWith(quantity: newQuantity);
      if (getPersistenceSupportStatus()) {
        _updatePersistenceCart(_cartItemsList);
      }
    }
  }
}