shoppingcart_provider.dart
unknown
plain_text
a month ago
617 B
5
Indexable
import 'package:flutter/material.dart'; import '../model/Item.dart'; class ShoppingCart with ChangeNotifier { final List<Item> _shoppingList = []; double cartTotal = 0; List<Item> get cart => _shoppingList; void addItem(Item item) { _shoppingList.add(item); cartTotal = cartTotal + item.price; notifyListeners(); } void removeAll() { _shoppingList.clear(); cartTotal = 0; notifyListeners(); } Item removeItem(int i) { Item removed = _shoppingList.removeAt(i); cartTotal -= removed.price; notifyListeners(); return removed; } }
Editor is loading...
Leave a Comment