shoppingcart_provider.dart
Anonymous
plain_text
03/17/2025 3:35 AM
824 B
19
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