feat: move inventory to own view model, add signing keys

This commit is contained in:
2026-07-28 01:11:27 +02:00
parent 1d687235f4
commit e53bdf1c38
14 changed files with 620 additions and 257 deletions
+61
View File
@@ -0,0 +1,61 @@
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<Product> _products = [];
List<Product> get products => _products;
Future<void> load() async {
_products = await productService.getProducts();
notifyListeners();
}
Future<void> 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<void> 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();
}
}