From 4bbd70464fe4baf1713de69bd1b663d20b1a1ddd Mon Sep 17 00:00:00 2001 From: esche Date: Sun, 25 Jun 2023 12:04:17 +0200 Subject: [PATCH] restructured sample data again --- Frontend-user/lib/basket.dart | 9 +- Frontend-user/lib/finance.dart | 7 +- Frontend-user/lib/main.dart | 2 +- Frontend-user/lib/sample_data.dart | 177 ++++++++++++++++++++--------- 4 files changed, 135 insertions(+), 60 deletions(-) diff --git a/Frontend-user/lib/basket.dart b/Frontend-user/lib/basket.dart index 8acedb1..cd108f7 100644 --- a/Frontend-user/lib/basket.dart +++ b/Frontend-user/lib/basket.dart @@ -9,18 +9,21 @@ import 'sample_data.dart'; */ class ShowBasket extends StatelessWidget { - ShowBasket({super.key}); + final Transaction transaction; + + const ShowBasket({super.key, required this.transaction}); @override Widget build(BuildContext context) { return ListView.builder( itemCount: null, itemBuilder: (context, index) { - if (index < SampleData().basket.purchases.length) { + if (index < transaction.basket!.length) { return Card( child: ListTile( leading: const Icon(Icons.abc), - title: Text(SampleData().basket.purchases[index].product.name), + title: Text( + transaction.basket![index].products.name), //better null check //trailing: Text(), ), ); diff --git a/Frontend-user/lib/finance.dart b/Frontend-user/lib/finance.dart index dedb548..2167233 100644 --- a/Frontend-user/lib/finance.dart +++ b/Frontend-user/lib/finance.dart @@ -70,12 +70,13 @@ class Finance extends StatelessWidget { ) : null, onTap: () { - if (SampleData().transactions[index].type == - TransaktionArt.einkauf) { + if (SampleData().transactions[index].basket != null) { showBottomSheet( context: context, builder: (BuildContext context) { - return ShowBasket(); + return ShowBasket( + transaction: + SampleData().transactions[index]); }); } })); diff --git a/Frontend-user/lib/main.dart b/Frontend-user/lib/main.dart index a383cfa..1861776 100644 --- a/Frontend-user/lib/main.dart +++ b/Frontend-user/lib/main.dart @@ -81,7 +81,7 @@ class _MyHomePageState extends State { alignment: Alignment.center, child: Text('Page $test'), ), - Finance(), + const Finance(), ListView(children: const [ ListTile( leading: Icon(Icons.dark_mode), diff --git a/Frontend-user/lib/sample_data.dart b/Frontend-user/lib/sample_data.dart index 50787f6..5483d78 100644 --- a/Frontend-user/lib/sample_data.dart +++ b/Frontend-user/lib/sample_data.dart @@ -19,8 +19,10 @@ class Transaction { int amount; TransaktionArt type; DateTime date; + List? basket; String? description; - Transaction(this.type, this.amount, this.date, [this.description]); + Transaction(this.type, this.amount, this.date, + {this.description, this.basket}); } class Product { @@ -33,53 +35,13 @@ class Product { const Product(this.name, this.unit, this.price, this.vat, this.category); } -class Purchase { - Product product; - int amount; - Purchase(this.product, this.amount); -} - class Basket { - List purchases; - int price; - Basket(this.purchases, this.price); + Product products; + int amount; + Basket(this.products, this.amount); } -//sample data class SampleData { - final List transactions = [ - Transaction(TransaktionArt.monatlBeitrag, 0, now), - Transaction(TransaktionArt.aufladung, 2042, now), - Transaction( - TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))), - Transaction(TransaktionArt.korrektur, 2332, - now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs'), - Transaction(TransaktionArt.monatlBeitrag, 0, now), - Transaction(TransaktionArt.aufladung, 2042, now), - Transaction( - TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))), - Transaction(TransaktionArt.korrektur, 2332, - now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs'), - Transaction(TransaktionArt.monatlBeitrag, 0, now), - Transaction(TransaktionArt.aufladung, 2042, now), - Transaction( - TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))), - Transaction(TransaktionArt.korrektur, 2332, - now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs'), - Transaction(TransaktionArt.monatlBeitrag, 0, now), - Transaction(TransaktionArt.aufladung, 2042, now), - Transaction( - TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))), - Transaction(TransaktionArt.korrektur, 2332, - now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs'), - Transaction(TransaktionArt.monatlBeitrag, 0, now), - Transaction(TransaktionArt.aufladung, 2042, now), - Transaction( - TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))), - Transaction(TransaktionArt.korrektur, 2332, - now.subtract(const Duration(hours: 5)), 'Korrektur des Warenkorbs') - ]; - static const List products = [ Product('Apfel', Unit.stueck, 0.23, 7, Category.obstUndGemuese), Product('Mehl', Unit.menge, 0.003, 19, Category.kochenUndBacken), @@ -90,13 +52,122 @@ 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); + static List basket = [ + Basket(products[0], 20), + Basket(products[1], 2200), + Basket(products[2], 2), + Basket(products[3], 1), + Basket(products[4], 1), + Basket(products[5], 2), + Basket(products[6], 222) + ]; + + static List basket2 = [ + Basket(products[0], 22), + Basket(products[1], 2241), + Basket(products[3], 2), + Basket(products[4], 4), + Basket(products[6], 2) + ]; + + static List basket3 = [ + Basket(products[0], -2), + Basket(products[1], 21), + Basket(products[3], -4), + Basket(products[4], 1), + Basket(products[6], 5) + ]; + + List transactions = [ + Transaction( + TransaktionArt.monatlBeitrag, + 0, + now, + ), + Transaction( + TransaktionArt.aufladung, + 2042, + now, + ), + Transaction( + TransaktionArt.einkauf, + -2442, + now.subtract(const Duration(days: 2)), + ), + Transaction( + TransaktionArt.korrektur, + 2332, + now.subtract(const Duration(hours: 5)), + description: 'Korrektur des Warenkorbs', + basket: basket3, + ), + Transaction( + TransaktionArt.monatlBeitrag, + 0, + now, + ), + Transaction( + TransaktionArt.aufladung, + 2042, + now, + ), + Transaction( + TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2)), + basket: basket2), + Transaction( + TransaktionArt.korrektur, 2332, now.subtract(const Duration(hours: 5)), + description: 'Korrektur des Warenkorbs'), + Transaction( + TransaktionArt.monatlBeitrag, + 0, + now, + ), + Transaction( + TransaktionArt.aufladung, + 2042, + now, + ), + Transaction( + TransaktionArt.einkauf, + -2442, + now.subtract(const Duration(days: 2)), + basket: basket, + ), + Transaction( + TransaktionArt.korrektur, 2332, now.subtract(const Duration(hours: 5)), + description: 'Korrektur des Warenkorbs'), + Transaction( + TransaktionArt.monatlBeitrag, + 0, + now, + ), + Transaction( + TransaktionArt.aufladung, + 2042, + now, + ), + Transaction( + TransaktionArt.einkauf, -2442, now.subtract(const Duration(days: 2))), + Transaction( + TransaktionArt.korrektur, 2332, now.subtract(const Duration(hours: 5)), + description: 'Korrektur des Warenkorbs'), + Transaction( + TransaktionArt.monatlBeitrag, + 0, + now, + ), + Transaction( + TransaktionArt.aufladung, + 2042, + now, + ), + Transaction( + TransaktionArt.einkauf, + -2442, + now.subtract(const Duration(days: 2)), + ), + Transaction( + TransaktionArt.korrektur, 2332, now.subtract(const Duration(hours: 5)), + description: 'Korrektur des Warenkorbs'), + ]; }