restructured sample data
This commit is contained in:
parent
d97f1fbb1c
commit
d9bf3c4fea
3 changed files with 129 additions and 119 deletions
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'sample_data.dart';
|
||||
|
||||
/* todo:
|
||||
- Flag für Ansicht/Bearbeitung
|
||||
|
@ -7,74 +8,19 @@ import 'package:flutter/material.dart';
|
|||
- 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);
|
||||
}
|
||||
|
||||
class Basket {
|
||||
List<Purchase> purchases;
|
||||
int price;
|
||||
Basket(this.purchases, this.price);
|
||||
}
|
||||
|
||||
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)
|
||||
];
|
||||
|
||||
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);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemCount: null,
|
||||
itemBuilder: (context, index) {
|
||||
if (index < basket.purchases.length) {
|
||||
if (index < SampleData().basket.purchases.length) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.abc),
|
||||
title: Text(basket.purchases[index].product.name),
|
||||
title: Text(SampleData().basket.purchases[index].product.name),
|
||||
//trailing: Text(),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:intl/intl.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'basket.dart';
|
||||
import 'sample_data.dart';
|
||||
|
||||
/*
|
||||
todo:
|
||||
|
@ -13,50 +14,8 @@ todo:
|
|||
- monatliche Aufladung: ausstehende Beträge
|
||||
*/
|
||||
|
||||
enum Type { monatlBeitrag, aufladung, einkauf, korrektur }
|
||||
|
||||
final now = DateTime.now();
|
||||
|
||||
class Transaction {
|
||||
int id = 0;
|
||||
int amount;
|
||||
Type type;
|
||||
DateTime date;
|
||||
String? description;
|
||||
Transaction(this.type, this.amount, this.date, [this.description]);
|
||||
}
|
||||
|
||||
//sample data
|
||||
class Finance extends StatelessWidget {
|
||||
final List<Transaction> transactions = [
|
||||
Transaction(Type.monatlBeitrag, 0, now),
|
||||
Transaction(Type.aufladung, 2042, now),
|
||||
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
'Korrektur des Warenkorbs'),
|
||||
Transaction(Type.monatlBeitrag, 0, now),
|
||||
Transaction(Type.aufladung, 2042, now),
|
||||
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
'Korrektur des Warenkorbs'),
|
||||
Transaction(Type.monatlBeitrag, 0, now),
|
||||
Transaction(Type.aufladung, 2042, now),
|
||||
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
'Korrektur des Warenkorbs'),
|
||||
Transaction(Type.monatlBeitrag, 0, now),
|
||||
Transaction(Type.aufladung, 2042, now),
|
||||
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
'Korrektur des Warenkorbs'),
|
||||
Transaction(Type.monatlBeitrag, 0, now),
|
||||
Transaction(Type.aufladung, 2042, now),
|
||||
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
'Korrektur des Warenkorbs')
|
||||
];
|
||||
|
||||
Finance({super.key});
|
||||
const Finance({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -81,13 +40,15 @@ class Finance extends StatelessWidget {
|
|||
body: ListView.builder(
|
||||
itemCount: null,
|
||||
itemBuilder: (context, index) {
|
||||
if (index < transactions.length) {
|
||||
if (index < SampleData().transactions.length) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: getIcon(transactions[index].type),
|
||||
title: Text(gettitle(transactions[index].type)),
|
||||
leading: getIcon(SampleData().transactions[index].type),
|
||||
title: Text(
|
||||
gettitle(SampleData().transactions[index].type)),
|
||||
subtitle: getSubtitle(index),
|
||||
trailing: transactions[index].type == Type.einkauf
|
||||
trailing: SampleData().transactions[index].type ==
|
||||
TransaktionArt.einkauf
|
||||
? PopupMenuButton(
|
||||
onSelected: (value) {},
|
||||
itemBuilder: (BuildContext context) =>
|
||||
|
@ -109,7 +70,8 @@ class Finance extends StatelessWidget {
|
|||
)
|
||||
: null,
|
||||
onTap: () {
|
||||
if (transactions[index].type == Type.einkauf) {
|
||||
if (SampleData().transactions[index].type ==
|
||||
TransaktionArt.einkauf) {
|
||||
showBottomSheet(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
|
@ -123,40 +85,40 @@ class Finance extends StatelessWidget {
|
|||
}));
|
||||
}
|
||||
|
||||
String gettitle(Type art) {
|
||||
String gettitle(TransaktionArt art) {
|
||||
switch (art) {
|
||||
case Type.aufladung:
|
||||
case TransaktionArt.aufladung:
|
||||
return 'Aufladung';
|
||||
case Type.einkauf:
|
||||
case TransaktionArt.einkauf:
|
||||
return 'Einkauf';
|
||||
case Type.korrektur:
|
||||
case TransaktionArt.korrektur:
|
||||
return 'Korrektur';
|
||||
case Type.monatlBeitrag:
|
||||
case TransaktionArt.monatlBeitrag:
|
||||
return 'monatlicher Beitrag';
|
||||
}
|
||||
}
|
||||
|
||||
Text getSubtitle(int index) {
|
||||
String text = '${transactions[index].amount / 100}';
|
||||
String text = '${SampleData().transactions[index].amount / 100}';
|
||||
text += '€ ';
|
||||
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
|
||||
.format(transactions[index].date);
|
||||
if (transactions[index].description != null) {
|
||||
(text += '\n${transactions[index].description}');
|
||||
.format(SampleData().transactions[index].date);
|
||||
if (SampleData().transactions[index].description != null) {
|
||||
(text += '\n${SampleData().transactions[index].description}');
|
||||
}
|
||||
|
||||
return Text(text);
|
||||
}
|
||||
|
||||
Icon getIcon(Type art) {
|
||||
Icon getIcon(TransaktionArt art) {
|
||||
switch (art) {
|
||||
case Type.aufladung:
|
||||
case TransaktionArt.aufladung:
|
||||
return const Icon(Icons.savings);
|
||||
case Type.einkauf:
|
||||
case TransaktionArt.einkauf:
|
||||
return const Icon(Icons.shopping_basket);
|
||||
case Type.korrektur:
|
||||
case TransaktionArt.korrektur:
|
||||
return const Icon(Icons.priority_high);
|
||||
case Type.monatlBeitrag:
|
||||
case TransaktionArt.monatlBeitrag:
|
||||
return const Icon(Icons.payment);
|
||||
}
|
||||
}
|
||||
|
|
102
Frontend-user/lib/sample_data.dart
Normal file
102
Frontend-user/lib/sample_data.dart
Normal file
|
@ -0,0 +1,102 @@
|
|||
final now = DateTime.now();
|
||||
|
||||
enum TransaktionArt { monatlBeitrag, aufladung, einkauf, korrektur }
|
||||
|
||||
enum Unit { stueck, menge }
|
||||
|
||||
enum Category {
|
||||
obstUndGemuese,
|
||||
brotCerealienUndAufstriche,
|
||||
getraenke,
|
||||
drogerieUndHaushalt,
|
||||
kochenUndBacken,
|
||||
oeleSossenUndGewuerze,
|
||||
suessesUndKnabbereien
|
||||
}
|
||||
|
||||
class Transaction {
|
||||
int id = 0;
|
||||
int amount;
|
||||
TransaktionArt type;
|
||||
DateTime date;
|
||||
String? description;
|
||||
Transaction(this.type, this.amount, this.date, [this.description]);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
class Basket {
|
||||
List<Purchase> purchases;
|
||||
int price;
|
||||
Basket(this.purchases, this.price);
|
||||
}
|
||||
|
||||
//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),
|
||||
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)
|
||||
];
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in a new issue