2023-06-23 10:54:25 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/* todo:
|
|
|
|
- Flag für Ansicht/Bearbeitung
|
|
|
|
- individuelle Icons je nach Kategorie
|
|
|
|
- Pfand
|
|
|
|
- Gesamtpreis
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum Unit { stueck, menge }
|
|
|
|
|
|
|
|
enum Category {
|
|
|
|
obstUndGemuese,
|
|
|
|
brotCerealienUndAufstriche,
|
|
|
|
getraenke,
|
|
|
|
drogerieUndHaushalt,
|
|
|
|
kochenUndBacken,
|
|
|
|
oeleSossenUndGewuerze,
|
|
|
|
suessesUndKnabbereien
|
|
|
|
}
|
|
|
|
|
|
|
|
class Product {
|
|
|
|
final int id = 0;
|
|
|
|
final String name;
|
|
|
|
final Unit unit;
|
|
|
|
final double price; //pro Kilogramm oder Stück
|
|
|
|
final double vat;
|
|
|
|
final Category category;
|
|
|
|
const Product(this.name, this.unit, this.price, this.vat, this.category);
|
|
|
|
}
|
|
|
|
|
|
|
|
class Purchase {
|
|
|
|
Product product;
|
|
|
|
int amount;
|
|
|
|
Purchase(this.product, this.amount);
|
|
|
|
}
|
|
|
|
|
2023-06-23 12:12:46 +02:00
|
|
|
class Basket {
|
|
|
|
List<Purchase> purchases;
|
|
|
|
int price;
|
|
|
|
Basket(this.purchases, this.price);
|
|
|
|
}
|
|
|
|
|
2023-06-23 10:54:25 +02:00
|
|
|
class ShowBasket extends StatelessWidget {
|
|
|
|
ShowBasket({super.key});
|
|
|
|
|
|
|
|
//sample data
|
|
|
|
static const List<Product> products = [
|
|
|
|
Product('Apfel', Unit.stueck, 0.23, 7, Category.obstUndGemuese),
|
|
|
|
Product('Mehl', Unit.menge, 0.003, 19, Category.kochenUndBacken),
|
|
|
|
Product('Brot', Unit.stueck, 1.23, 7, Category.brotCerealienUndAufstriche),
|
|
|
|
Product('Milch', Unit.stueck, 2.23, 3, Category.getraenke),
|
|
|
|
Product('Zahnpasta', Unit.stueck, 0.23, 7, Category.drogerieUndHaushalt),
|
|
|
|
Product('Pfeffer', Unit.stueck, 0.23, 7, Category.oeleSossenUndGewuerze),
|
|
|
|
Product('Schokolade', Unit.menge, 0.23, 7, Category.suessesUndKnabbereien)
|
|
|
|
];
|
|
|
|
|
2023-06-23 12:12:46 +02:00
|
|
|
Basket basket = Basket([
|
2023-06-23 10:54:25 +02:00
|
|
|
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)
|
2023-06-23 12:12:46 +02:00
|
|
|
], 304);
|
2023-06-23 10:54:25 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListView.builder(
|
|
|
|
itemCount: null,
|
|
|
|
itemBuilder: (context, index) {
|
2023-06-23 12:12:46 +02:00
|
|
|
if (index < basket.purchases.length) {
|
2023-06-23 10:54:25 +02:00
|
|
|
return Card(
|
|
|
|
child: ListTile(
|
|
|
|
leading: const Icon(Icons.abc),
|
2023-06-23 12:12:46 +02:00
|
|
|
title: Text(basket.purchases[index].product.name),
|
2023-06-23 10:54:25 +02:00
|
|
|
//trailing: Text(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|