restructured sample data again

This commit is contained in:
esche 2023-06-25 12:04:17 +02:00
parent 597db5d51f
commit 4bbd70464f
4 changed files with 135 additions and 60 deletions

View file

@ -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(),
),
);

View file

@ -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]);
});
}
}));

View file

@ -81,7 +81,7 @@ class _MyHomePageState extends State<MyHomePage> {
alignment: Alignment.center,
child: Text('Page $test'),
),
Finance(),
const Finance(),
ListView(children: const <Widget>[
ListTile(
leading: Icon(Icons.dark_mode),

View file

@ -19,8 +19,10 @@ class Transaction {
int amount;
TransaktionArt type;
DateTime date;
List<Basket>? 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<Purchase> purchases;
int price;
Basket(this.purchases, this.price);
Product products;
int amount;
Basket(this.products, this.amount);
}
//sample data
class SampleData {
final List<Transaction> 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<Product> 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 = [
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<Basket> basket2 = [
Basket(products[0], 22),
Basket(products[1], 2241),
Basket(products[3], 2),
Basket(products[4], 4),
Basket(products[6], 2)
];
static List<Basket> basket3 = [
Basket(products[0], -2),
Basket(products[1], 21),
Basket(products[3], -4),
Basket(products[4], 1),
Basket(products[6], 5)
];
List<Transaction> 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'),
];
}