add structure
This commit is contained in:
49
lib/vo/reg.dart
Normal file
49
lib/vo/reg.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
import 'product.dart';
|
||||
|
||||
class Reg {
|
||||
String name = "", address = "", type = "";
|
||||
int numberOfShops = 0;
|
||||
|
||||
final String sellerID;
|
||||
final String buyerID;
|
||||
final List<Product> products;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
var _products = [];
|
||||
products.forEach((p) => _products.add(p.toMap()));
|
||||
return {
|
||||
'products': _products,
|
||||
'seller_id': sellerID,
|
||||
'buyer_id': buyerID,
|
||||
};
|
||||
}
|
||||
|
||||
Reg(this.sellerID, this.buyerID, this.products);
|
||||
|
||||
void addProduct(Product product) {
|
||||
var _product = _get(product.id);
|
||||
if (_product == null) {
|
||||
_product = product;
|
||||
products.add(product);
|
||||
}
|
||||
_product.dailySale = product.dailySale;
|
||||
_product.storageCapacity = product.storageCapacity;
|
||||
}
|
||||
|
||||
void deleteProduct(Product product) {
|
||||
var _product = _get(product.id);
|
||||
if (_product == null) {
|
||||
return;
|
||||
}
|
||||
products.remove(_product);
|
||||
}
|
||||
|
||||
Product _get(String id) {
|
||||
try {
|
||||
return products.firstWhere((p) => p.id == id);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user