import 'package:flutter/foundation.dart'; import '../models/product.dart'; import '../services/product_service.dart'; class InventoryViewModel extends ChangeNotifier { final ProductService productService; InventoryViewModel({required this.productService}); List _products = []; List get products => _products; Future load() async { _products = await productService.getProducts(); notifyListeners(); } Future decreaseStock(String productId, int amount) async { await productService.decreaseStock(productId, amount); final index = _products.indexWhere((product) => product.id == productId); if (index != -1) { _products[index] = _products[index].copyWith( stockQuantity: _products[index].stockQuantity - amount, ); } notifyListeners(); } Future increaseStock(String productId, int amount) async { await productService.increaseStock(productId, amount); final index = _products.indexWhere((product) => product.id == productId); if (index != -1) { _products[index] = _products[index].copyWith( stockQuantity: _products[index].stockQuantity + amount, ); } notifyListeners(); } }