forked from mgl_crew/Mitgliederladen
adding a structure for future basket
This commit is contained in:
parent
3ab6cd5690
commit
45f76eab17
3 changed files with 129 additions and 46 deletions
81
Frontend-user/lib/basket.dart
Normal file
81
Frontend-user/lib/basket.dart
Normal file
|
@ -0,0 +1,81 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
/* todo:
|
||||
- Flag für Ansicht/Bearbeitung
|
||||
- individuelle Icons je nach Kategorie
|
||||
- Pfand
|
||||
- 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 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)
|
||||
];
|
||||
|
||||
final List<Purchase> 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)
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemCount: null,
|
||||
itemBuilder: (context, index) {
|
||||
if (index < basket.length) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.abc),
|
||||
title: Text(basket[index].product.name),
|
||||
//trailing: Text(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'basket.dart';
|
||||
|
||||
/*
|
||||
todo:
|
||||
|
@ -12,45 +13,46 @@ todo:
|
|||
- monatliche Aufladung: ausstehende Beträge
|
||||
*/
|
||||
|
||||
enum Art { monatlBeitrag, aufladung, einkauf, korrektur }
|
||||
enum Type { monatlBeitrag, aufladung, einkauf, korrektur }
|
||||
|
||||
final now = DateTime.now();
|
||||
|
||||
class Transaction {
|
||||
int betrag;
|
||||
Art art;
|
||||
DateTime datum;
|
||||
String? beschreibung;
|
||||
Transaction(this.art, this.betrag, this.datum, [this.beschreibung]);
|
||||
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(Art.monatlBeitrag, 0, now),
|
||||
Transaction(Art.aufladung, 2042, now),
|
||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
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(Art.monatlBeitrag, 0, now),
|
||||
Transaction(Art.aufladung, 2042, now),
|
||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
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(Art.monatlBeitrag, 0, now),
|
||||
Transaction(Art.aufladung, 2042, now),
|
||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
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(Art.monatlBeitrag, 0, now),
|
||||
Transaction(Art.aufladung, 2042, now),
|
||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
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(Art.monatlBeitrag, 0, now),
|
||||
Transaction(Art.aufladung, 2042, now),
|
||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||
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')
|
||||
];
|
||||
|
||||
|
@ -82,10 +84,10 @@ class Finance extends StatelessWidget {
|
|||
if (index < transactions.length) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: getIcon(transactions[index].art),
|
||||
title: Text(gettitle(transactions[index].art)),
|
||||
leading: getIcon(transactions[index].type),
|
||||
title: Text(gettitle(transactions[index].type)),
|
||||
subtitle: getSubtitle(index),
|
||||
trailing: transactions[index].art == Art.einkauf
|
||||
trailing: transactions[index].type == Type.einkauf
|
||||
? PopupMenuButton(
|
||||
onSelected: (value) {},
|
||||
itemBuilder: (BuildContext context) =>
|
||||
|
@ -107,11 +109,11 @@ class Finance extends StatelessWidget {
|
|||
)
|
||||
: null,
|
||||
onTap: () {
|
||||
if (transactions[index].art == Art.einkauf) {
|
||||
if (transactions[index].type == Type.einkauf) {
|
||||
showBottomSheet(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return const SizedBox.expand();
|
||||
return ShowBasket();
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
@ -121,40 +123,40 @@ class Finance extends StatelessWidget {
|
|||
}));
|
||||
}
|
||||
|
||||
String gettitle(Art art) {
|
||||
String gettitle(Type art) {
|
||||
switch (art) {
|
||||
case Art.aufladung:
|
||||
case Type.aufladung:
|
||||
return 'Aufladung';
|
||||
case Art.einkauf:
|
||||
case Type.einkauf:
|
||||
return 'Einkauf';
|
||||
case Art.korrektur:
|
||||
case Type.korrektur:
|
||||
return 'Korrektur';
|
||||
case Art.monatlBeitrag:
|
||||
case Type.monatlBeitrag:
|
||||
return 'monatlicher Beitrag';
|
||||
}
|
||||
}
|
||||
|
||||
Text getSubtitle(int index) {
|
||||
String text = '${transactions[index].betrag / 100}';
|
||||
String text = '${transactions[index].amount / 100}';
|
||||
text += '€ ';
|
||||
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
|
||||
.format(transactions[index].datum);
|
||||
if (transactions[index].beschreibung != null) {
|
||||
(text += '\n${transactions[index].beschreibung}');
|
||||
.format(transactions[index].date);
|
||||
if (transactions[index].description != null) {
|
||||
(text += '\n${transactions[index].description}');
|
||||
}
|
||||
|
||||
return Text(text);
|
||||
}
|
||||
|
||||
Icon getIcon(Art art) {
|
||||
Icon getIcon(Type art) {
|
||||
switch (art) {
|
||||
case Art.aufladung:
|
||||
case Type.aufladung:
|
||||
return const Icon(Icons.savings);
|
||||
case Art.einkauf:
|
||||
case Type.einkauf:
|
||||
return const Icon(Icons.shopping_basket);
|
||||
case Art.korrektur:
|
||||
case Type.korrektur:
|
||||
return const Icon(Icons.priority_high);
|
||||
case Art.monatlBeitrag:
|
||||
case Type.monatlBeitrag:
|
||||
return const Icon(Icons.payment);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class MyApp extends StatelessWidget {
|
|||
brightness: Brightness.dark,
|
||||
seedColor: const Color(0xff5f7c61),
|
||||
)),
|
||||
themeMode: ThemeMode.system,
|
||||
themeMode: ThemeMode.dark,
|
||||
home: const MyHomePage(),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue