applyDiscount method

void applyDiscount(
  1. String productId,
  2. List<ProductVariant> variants,
  3. double discount
)

applyDiscount use this method when you have case where you have to apply discount on specific product. Otherwise you can also apply discount the time of adding product into the cart. Check addToCart example for more info.

Implementation

void applyDiscount(
    String productId, List<ProductVariant> variants, double discount) {
  var itemIndex = getProductIndex(productId, variants);

  if (itemIndex != -1) {
    _cartItemsList[itemIndex] =
        _cartItemsList[itemIndex].copyWith(discount: discount);
  }
}