feature/mockup-datastore #3

Closed
fdenzer wants to merge 2 commits from feature/mockup-datastore into main
2 changed files with 25 additions and 12 deletions
Showing only changes of commit 96c89170a0 - Show all commits

View file

@ -20,7 +20,7 @@ class ShowBasket extends StatelessWidget {
return Card(
child: ListTile(
leading: const Icon(Icons.abc),
title: Text(SampleData().basket.purchases[index].product.name),
title: Text(SampleData().basket.purchases.keys.elementAt(index).name),
//trailing: Text(),
),
);

View file

@ -40,9 +40,22 @@ class Purchase {
}
class Basket {
List<Purchase> purchases;
int price;
Map<Product, int> purchases;
double 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
@ -90,13 +103,13 @@ class SampleData {
Product('Schokolade', Unit.menge, 0.23, 7, Category.suessesUndKnabbereien)
];
Basket basket = Basket([
Purchase(products[0], 20),
Purchase(products[1], 2200),
Purchase(products[2], 2),
Purchase(products[3], 1),
Purchase(products[4], 1),
Purchase(products[5], 2),
Purchase(products[6], 202)
], 304);
Basket basket = Basket({
products[0]: 20,
products[1]: 2200,
products[2]: 2,
products[3]: 1,
products[4]: 1,
products[5]: 2,
products[6]: 202
}, 304);
}