forked from mgl_crew/Mitgliederladen
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 'package:flutter/material.dart';
|
||||||
|
import 'sample_data.dart';
|
||||||
|
|
||||||
/* todo:
|
/* todo:
|
||||||
- Flag für Ansicht/Bearbeitung
|
- Flag für Ansicht/Bearbeitung
|
||||||
|
@ -7,74 +8,19 @@ import 'package:flutter/material.dart';
|
||||||
- Gesamtpreis
|
- 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 {
|
class ShowBasket extends StatelessWidget {
|
||||||
ShowBasket({super.key});
|
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
|
@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 < basket.purchases.length) {
|
if (index < SampleData().basket.purchases.length) {
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: const Icon(Icons.abc),
|
leading: const Icon(Icons.abc),
|
||||||
title: Text(basket.purchases[index].product.name),
|
title: Text(SampleData().basket.purchases[index].product.name),
|
||||||
//trailing: Text(),
|
//trailing: Text(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:intl/date_symbol_data_local.dart';
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
import 'basket.dart';
|
import 'basket.dart';
|
||||||
|
import 'sample_data.dart';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
todo:
|
todo:
|
||||||
|
@ -13,50 +14,8 @@ todo:
|
||||||
- monatliche Aufladung: ausstehende Beträge
|
- 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 {
|
class Finance extends StatelessWidget {
|
||||||
final List<Transaction> transactions = [
|
const Finance({super.key});
|
||||||
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});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -81,13 +40,15 @@ class Finance extends StatelessWidget {
|
||||||
body: ListView.builder(
|
body: ListView.builder(
|
||||||
itemCount: null,
|
itemCount: null,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
if (index < transactions.length) {
|
if (index < SampleData().transactions.length) {
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: getIcon(transactions[index].type),
|
leading: getIcon(SampleData().transactions[index].type),
|
||||||
title: Text(gettitle(transactions[index].type)),
|
title: Text(
|
||||||
|
gettitle(SampleData().transactions[index].type)),
|
||||||
subtitle: getSubtitle(index),
|
subtitle: getSubtitle(index),
|
||||||
trailing: transactions[index].type == Type.einkauf
|
trailing: SampleData().transactions[index].type ==
|
||||||
|
TransaktionArt.einkauf
|
||||||
? PopupMenuButton(
|
? PopupMenuButton(
|
||||||
onSelected: (value) {},
|
onSelected: (value) {},
|
||||||
itemBuilder: (BuildContext context) =>
|
itemBuilder: (BuildContext context) =>
|
||||||
|
@ -109,7 +70,8 @@ class Finance extends StatelessWidget {
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (transactions[index].type == Type.einkauf) {
|
if (SampleData().transactions[index].type ==
|
||||||
|
TransaktionArt.einkauf) {
|
||||||
showBottomSheet(
|
showBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
|
@ -123,40 +85,40 @@ class Finance extends StatelessWidget {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
String gettitle(Type art) {
|
String gettitle(TransaktionArt art) {
|
||||||
switch (art) {
|
switch (art) {
|
||||||
case Type.aufladung:
|
case TransaktionArt.aufladung:
|
||||||
return 'Aufladung';
|
return 'Aufladung';
|
||||||
case Type.einkauf:
|
case TransaktionArt.einkauf:
|
||||||
return 'Einkauf';
|
return 'Einkauf';
|
||||||
case Type.korrektur:
|
case TransaktionArt.korrektur:
|
||||||
return 'Korrektur';
|
return 'Korrektur';
|
||||||
case Type.monatlBeitrag:
|
case TransaktionArt.monatlBeitrag:
|
||||||
return 'monatlicher Beitrag';
|
return 'monatlicher Beitrag';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text getSubtitle(int index) {
|
Text getSubtitle(int index) {
|
||||||
String text = '${transactions[index].amount / 100}';
|
String text = '${SampleData().transactions[index].amount / 100}';
|
||||||
text += '€ ';
|
text += '€ ';
|
||||||
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
|
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
|
||||||
.format(transactions[index].date);
|
.format(SampleData().transactions[index].date);
|
||||||
if (transactions[index].description != null) {
|
if (SampleData().transactions[index].description != null) {
|
||||||
(text += '\n${transactions[index].description}');
|
(text += '\n${SampleData().transactions[index].description}');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Text(text);
|
return Text(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Icon getIcon(Type art) {
|
Icon getIcon(TransaktionArt art) {
|
||||||
switch (art) {
|
switch (art) {
|
||||||
case Type.aufladung:
|
case TransaktionArt.aufladung:
|
||||||
return const Icon(Icons.savings);
|
return const Icon(Icons.savings);
|
||||||
case Type.einkauf:
|
case TransaktionArt.einkauf:
|
||||||
return const Icon(Icons.shopping_basket);
|
return const Icon(Icons.shopping_basket);
|
||||||
case Type.korrektur:
|
case TransaktionArt.korrektur:
|
||||||
return const Icon(Icons.priority_high);
|
return const Icon(Icons.priority_high);
|
||||||
case Type.monatlBeitrag:
|
case TransaktionArt.monatlBeitrag:
|
||||||
return const Icon(Icons.payment);
|
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