You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
705 B
29 lines
705 B
import 'package:get/get.dart';
|
|
|
|
import '../Models/produit.dart';
|
|
|
|
class ProductController extends GetxController {
|
|
final _products = <Product>[].obs;
|
|
|
|
List<Product> get products => _products.toList();
|
|
|
|
void setProducts(List<Product> productList) {
|
|
_products.clear();
|
|
_products.addAll(productList);
|
|
}
|
|
|
|
void addProduct(Product product) {
|
|
_products.add(product);
|
|
}
|
|
|
|
void updateProduct(Product updatedProduct) {
|
|
final index = _products.indexWhere((product) => product.id == updatedProduct.id);
|
|
if (index != -1) {
|
|
_products[index] = updatedProduct;
|
|
}
|
|
}
|
|
|
|
void deleteProduct(int ?productId) {
|
|
_products.removeWhere((product) => product.id == productId);
|
|
}
|
|
}
|
|
|