I have a map of CartItems which each contain an id, title, quantity, and price. I currently have a getter (itemCount) which returns the number of CartItems. But I would instead like the getter to return the sum of the quantities of all the CartItems in the map. Below is the relevant code snippet
class CartItem {
final String id;
final String title;
final int quantity;
final double price;
CartItem({this.id, this.title, this.quantity, this.price});
}
class Cart with ChangeNotifier {
Map<String, CartItem> items = {};
int get itemCount {
return items.length;
}