addToCart method

void addToCart(
  1. Car car
)

Implementation

void addToCart(Car car) {
  var isExist = _shoppingCart.where((element) => element.car.id == car.id);
  if (isExist.isEmpty) {
    _shoppingCart.add(Cart(
      car: car,
      quantity: 1,
    ));
  } else {
    isExist.first.quantity += 1;
  }

  notifyListeners();
}