forked from mgl_crew/Mitgliederladen
restructured sample data again
This commit is contained in:
parent
597db5d51f
commit
4bbd70464f
4 changed files with 135 additions and 60 deletions
|
@ -9,18 +9,21 @@ import 'sample_data.dart';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ShowBasket extends StatelessWidget {
|
class ShowBasket extends StatelessWidget {
|
||||||
ShowBasket({super.key});
|
final Transaction transaction;
|
||||||
|
|
||||||
|
const ShowBasket({super.key, required this.transaction});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: null,
|
itemCount: null,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
if (index < SampleData().basket.purchases.length) {
|
if (index < transaction.basket!.length) {
|
||||||
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(
|
||||||
|
transaction.basket![index].products.name), //better null check
|
||||||
//trailing: Text(),
|
//trailing: Text(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -70,12 +70,13 @@ class Finance extends StatelessWidget {
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (SampleData().transactions[index].type ==
|
if (SampleData().transactions[index].basket != null) {
|
||||||
TransaktionArt.einkauf) {
|
|
||||||
showBottomSheet(
|
showBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return ShowBasket();
|
return ShowBasket(
|
||||||
|
transaction:
|
||||||
|
SampleData().transactions[index]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -81,7 +81,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: Text('Page $test'),
|
child: Text('Page $test'),
|
||||||
),
|
),
|
||||||
Finance(),
|
const Finance(),
|
||||||
ListView(children: const <Widget>[
|
ListView(children: const <Widget>[
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: Icon(Icons.dark_mode),
|
leading: Icon(Icons.dark_mode),
|
||||||
|
|
|
@ -19,8 +19,10 @@ class Transaction {
|
||||||
int amount;
|
int amount;
|
||||||
TransaktionArt type;
|
TransaktionArt type;
|
||||||
DateTime date;
|
DateTime date;
|
||||||
|
List<Basket>? basket;
|
||||||
String? description;
|
String? description;
|
||||||
Transaction(this.type, this.amount, this.date, [this.description]);
|
Transaction(this.type, this.amount, this.date,
|
||||||
|
{this.description, this.basket});
|
||||||
}
|
}
|
||||||
|
|
||||||
class Product {
|
class Product {
|
||||||
|
@ -33,53 +35,13 @@ class Product {
|
||||||
const Product(this.name, this.unit, this.price, this.vat, this.category);
|
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 {
|
class Basket {
|
||||||
List<Purchase> purchases;
|
Product products;
|
||||||
int price;
|
int amount;
|
||||||
Basket(this.purchases, this.price);
|
Basket(this.products, this.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
//sample data
|
|
||||||
class SampleData {
|
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 = [
|
static const List<Product> products = [
|
||||||
Product('Apfel', Unit.stueck, 0.23, 7, Category.obstUndGemuese),
|
Product('Apfel', Unit.stueck, 0.23, 7, Category.obstUndGemuese),
|
||||||
Product('Mehl', Unit.menge, 0.003, 19, Category.kochenUndBacken),
|
Product('Mehl', Unit.menge, 0.003, 19, Category.kochenUndBacken),
|
||||||
|
@ -90,13 +52,122 @@ class SampleData {
|
||||||
Product('Schokolade', Unit.menge, 0.23, 7, Category.suessesUndKnabbereien)
|
Product('Schokolade', Unit.menge, 0.23, 7, Category.suessesUndKnabbereien)
|
||||||
];
|
];
|
||||||
|
|
||||||
Basket basket = Basket([
|
static List<Basket> basket = [
|
||||||
Purchase(products[0], 20),
|
Basket(products[0], 20),
|
||||||
Purchase(products[1], 2200),
|
Basket(products[1], 2200),
|
||||||
Purchase(products[2], 2),
|
Basket(products[2], 2),
|
||||||
Purchase(products[3], 1),
|
Basket(products[3], 1),
|
||||||
Purchase(products[4], 1),
|
Basket(products[4], 1),
|
||||||
Purchase(products[5], 2),
|
Basket(products[5], 2),
|
||||||
Purchase(products[6], 202)
|
Basket(products[6], 222)
|
||||||
], 304);
|
];
|
||||||
|
|
||||||
|
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'),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue