updateCouponPrice method

void updateCouponPrice(
  1. CouponRedeem coupon
)

Implementation

void updateCouponPrice(CouponRedeem coupon) {
  var checkout = viewState.value.data;
  bool isCouponExist = false;

  if (checkout != null) {
    for (var element in checkout.priceDetail) {
      if (element.label.toLowerCase() == "kupon promo") {
        element.value = coupon.amountValue.toDouble();
        isCouponExist = true;
        break;
      }
    }

    if (!isCouponExist) {
      checkout.priceDetail.add(
        PriceDetail(
          label: "Kupon promo",
          value: coupon.amountValue.toDouble(),
          type: "minus",
        ),
      );
    }
  }

  calculatePrice();
  update();
}