import 'package:hive_ce/hive.dart'; import '../models/cart_item_model.dart'; /// Cart local data source using Hive abstract class CartLocalDataSource { Future> getCartItems(); Future addToCart(CartItemModel item); Future updateQuantity(String productId, int quantity); Future removeFromCart(String productId); Future clearCart(); } class CartLocalDataSourceImpl implements CartLocalDataSource { final Box box; CartLocalDataSourceImpl(this.box); @override Future> getCartItems() async { return box.values.toList(); } @override Future addToCart(CartItemModel item) async { await box.put(item.productId, item); } @override Future updateQuantity(String productId, int quantity) async { final item = box.get(productId); if (item != null) { final updated = CartItemModel( productId: item.productId, productName: item.productName, price: item.price, quantity: quantity, imageUrl: item.imageUrl, addedAt: item.addedAt, ); await box.put(productId, updated); } } @override Future removeFromCart(String productId) async { await box.delete(productId); } @override Future clearCart() async { await box.clear(); } }