feature/mockup-datastore #3
2 changed files with 25 additions and 12 deletions
|
@ -20,7 +20,7 @@ class ShowBasket extends StatelessWidget {
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: const Icon(Icons.abc),
|
leading: const Icon(Icons.abc),
|
||||||
title: Text(SampleData().basket.purchases[index].product.name),
|
title: Text(SampleData().basket.purchases.keys.elementAt(index).name),
|
||||||
//trailing: Text(),
|
//trailing: Text(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -40,9 +40,22 @@ class Purchase {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Basket {
|
class Basket {
|
||||||
List<Purchase> purchases;
|
Map<Product, int> purchases;
|
||||||
int price;
|
double price;
|
||||||
|
|
||||||
Basket(this.purchases, this.price);
|
Basket(this.purchases, this.price);
|
||||||
|
|
||||||
|
void addItem(Product product, int quantity) {
|
||||||
|
if (purchases.containsKey(product)) {
|
||||||
|
purchases.update(product, (existingQuantity) => existingQuantity + quantity);
|
||||||
|
} else {
|
||||||
|
purchases[product] = quantity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeItem(Product product) {
|
||||||
|
purchases.remove(product);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//sample data
|
//sample data
|
||||||
|
@ -90,13 +103,13 @@ class SampleData {
|
||||||
Product('Schokolade', Unit.menge, 0.23, 7, Category.suessesUndKnabbereien)
|
Product('Schokolade', Unit.menge, 0.23, 7, Category.suessesUndKnabbereien)
|
||||||
];
|
];
|
||||||
|
|
||||||
Basket basket = Basket([
|
Basket basket = Basket({
|
||||||
Purchase(products[0], 20),
|
products[0]: 20,
|
||||||
Purchase(products[1], 2200),
|
products[1]: 2200,
|
||||||
Purchase(products[2], 2),
|
products[2]: 2,
|
||||||
Purchase(products[3], 1),
|
products[3]: 1,
|
||||||
Purchase(products[4], 1),
|
products[4]: 1,
|
||||||
Purchase(products[5], 2),
|
products[5]: 2,
|
||||||
Purchase(products[6], 202)
|
products[6]: 202
|
||||||
], 304);
|
}, 304);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue