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: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';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
todo:
|
todo:
|
||||||
|
@ -12,45 +13,46 @@ todo:
|
||||||
- monatliche Aufladung: ausstehende Beträge
|
- monatliche Aufladung: ausstehende Beträge
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum Art { monatlBeitrag, aufladung, einkauf, korrektur }
|
enum Type { monatlBeitrag, aufladung, einkauf, korrektur }
|
||||||
|
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
|
|
||||||
class Transaction {
|
class Transaction {
|
||||||
int betrag;
|
int id = 0;
|
||||||
Art art;
|
int amount;
|
||||||
DateTime datum;
|
Type type;
|
||||||
String? beschreibung;
|
DateTime date;
|
||||||
Transaction(this.art, this.betrag, this.datum, [this.beschreibung]);
|
String? description;
|
||||||
|
Transaction(this.type, this.amount, this.date, [this.description]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//sample data
|
//sample data
|
||||||
class Finance extends StatelessWidget {
|
class Finance extends StatelessWidget {
|
||||||
final List<Transaction> transactions = [
|
final List<Transaction> transactions = [
|
||||||
Transaction(Art.monatlBeitrag, 0, now),
|
Transaction(Type.monatlBeitrag, 0, now),
|
||||||
Transaction(Art.aufladung, 2042, now),
|
Transaction(Type.aufladung, 2042, now),
|
||||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||||
'Korrektur des Warenkorbs'),
|
'Korrektur des Warenkorbs'),
|
||||||
Transaction(Art.monatlBeitrag, 0, now),
|
Transaction(Type.monatlBeitrag, 0, now),
|
||||||
Transaction(Art.aufladung, 2042, now),
|
Transaction(Type.aufladung, 2042, now),
|
||||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||||
'Korrektur des Warenkorbs'),
|
'Korrektur des Warenkorbs'),
|
||||||
Transaction(Art.monatlBeitrag, 0, now),
|
Transaction(Type.monatlBeitrag, 0, now),
|
||||||
Transaction(Art.aufladung, 2042, now),
|
Transaction(Type.aufladung, 2042, now),
|
||||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||||
'Korrektur des Warenkorbs'),
|
'Korrektur des Warenkorbs'),
|
||||||
Transaction(Art.monatlBeitrag, 0, now),
|
Transaction(Type.monatlBeitrag, 0, now),
|
||||||
Transaction(Art.aufladung, 2042, now),
|
Transaction(Type.aufladung, 2042, now),
|
||||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||||
'Korrektur des Warenkorbs'),
|
'Korrektur des Warenkorbs'),
|
||||||
Transaction(Art.monatlBeitrag, 0, now),
|
Transaction(Type.monatlBeitrag, 0, now),
|
||||||
Transaction(Art.aufladung, 2042, now),
|
Transaction(Type.aufladung, 2042, now),
|
||||||
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
Transaction(Type.einkauf, -2442, now.subtract(const Duration(days: 2))),
|
||||||
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
Transaction(Type.korrektur, 2332, now.subtract(const Duration(hours: 5)),
|
||||||
'Korrektur des Warenkorbs')
|
'Korrektur des Warenkorbs')
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -82,10 +84,10 @@ class Finance extends StatelessWidget {
|
||||||
if (index < transactions.length) {
|
if (index < transactions.length) {
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: getIcon(transactions[index].art),
|
leading: getIcon(transactions[index].type),
|
||||||
title: Text(gettitle(transactions[index].art)),
|
title: Text(gettitle(transactions[index].type)),
|
||||||
subtitle: getSubtitle(index),
|
subtitle: getSubtitle(index),
|
||||||
trailing: transactions[index].art == Art.einkauf
|
trailing: transactions[index].type == Type.einkauf
|
||||||
? PopupMenuButton(
|
? PopupMenuButton(
|
||||||
onSelected: (value) {},
|
onSelected: (value) {},
|
||||||
itemBuilder: (BuildContext context) =>
|
itemBuilder: (BuildContext context) =>
|
||||||
|
@ -107,11 +109,11 @@ class Finance extends StatelessWidget {
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (transactions[index].art == Art.einkauf) {
|
if (transactions[index].type == Type.einkauf) {
|
||||||
showBottomSheet(
|
showBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext 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) {
|
switch (art) {
|
||||||
case Art.aufladung:
|
case Type.aufladung:
|
||||||
return 'Aufladung';
|
return 'Aufladung';
|
||||||
case Art.einkauf:
|
case Type.einkauf:
|
||||||
return 'Einkauf';
|
return 'Einkauf';
|
||||||
case Art.korrektur:
|
case Type.korrektur:
|
||||||
return 'Korrektur';
|
return 'Korrektur';
|
||||||
case Art.monatlBeitrag:
|
case Type.monatlBeitrag:
|
||||||
return 'monatlicher Beitrag';
|
return 'monatlicher Beitrag';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text getSubtitle(int index) {
|
Text getSubtitle(int index) {
|
||||||
String text = '${transactions[index].betrag / 100}';
|
String text = '${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].datum);
|
.format(transactions[index].date);
|
||||||
if (transactions[index].beschreibung != null) {
|
if (transactions[index].description != null) {
|
||||||
(text += '\n${transactions[index].beschreibung}');
|
(text += '\n${transactions[index].description}');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Text(text);
|
return Text(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
Icon getIcon(Art art) {
|
Icon getIcon(Type art) {
|
||||||
switch (art) {
|
switch (art) {
|
||||||
case Art.aufladung:
|
case Type.aufladung:
|
||||||
return const Icon(Icons.savings);
|
return const Icon(Icons.savings);
|
||||||
case Art.einkauf:
|
case Type.einkauf:
|
||||||
return const Icon(Icons.shopping_basket);
|
return const Icon(Icons.shopping_basket);
|
||||||
case Art.korrektur:
|
case Type.korrektur:
|
||||||
return const Icon(Icons.priority_high);
|
return const Icon(Icons.priority_high);
|
||||||
case Art.monatlBeitrag:
|
case Type.monatlBeitrag:
|
||||||
return const Icon(Icons.payment);
|
return const Icon(Icons.payment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class MyApp extends StatelessWidget {
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
seedColor: const Color(0xff5f7c61),
|
seedColor: const Color(0xff5f7c61),
|
||||||
)),
|
)),
|
||||||
themeMode: ThemeMode.system,
|
themeMode: ThemeMode.dark,
|
||||||
home: const MyHomePage(),
|
home: const MyHomePage(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue