Mitgliederladen/Frontend-user/lib/finance.dart

164 lines
5.6 KiB
Dart
Raw Normal View History

2023-06-12 23:06:20 +02:00
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:intl/date_symbol_data_local.dart';
2023-06-23 10:54:25 +02:00
import 'basket.dart';
2023-06-12 23:06:20 +02:00
/*
todo:
2023-06-16 15:36:13 +02:00
- Einkauf und Settings
2023-06-19 19:37:06 +02:00
- Warenkorb
- Aufladungen?
2023-06-12 23:06:20 +02:00
- farbliche Hervorhebungen
2023-06-19 19:37:06 +02:00
- semanticLabels, Screenreader
- monatliche Aufladung: ausstehende Beträge
2023-06-12 23:06:20 +02:00
*/
2023-06-23 10:54:25 +02:00
enum Type { monatlBeitrag, aufladung, einkauf, korrektur }
2023-06-12 23:06:20 +02:00
final now = DateTime.now();
class Transaction {
2023-06-23 10:54:25 +02:00
int id = 0;
int amount;
Type type;
DateTime date;
String? description;
Transaction(this.type, this.amount, this.date, [this.description]);
2023-06-12 23:06:20 +02:00
}
2023-06-19 12:12:18 +02:00
//sample data
2023-06-19 16:25:10 +02:00
class Finance extends StatelessWidget {
2023-06-12 23:06:20 +02:00
final List<Transaction> transactions = [
2023-06-23 10:54:25 +02:00
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)),
2023-06-16 15:36:13 +02:00
'Korrektur des Warenkorbs'),
2023-06-23 10:54:25 +02:00
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)),
2023-06-16 15:36:13 +02:00
'Korrektur des Warenkorbs'),
2023-06-23 10:54:25 +02:00
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)),
2023-06-16 15:36:13 +02:00
'Korrektur des Warenkorbs'),
2023-06-23 10:54:25 +02:00
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)),
2023-06-19 12:12:18 +02:00
'Korrektur des Warenkorbs'),
2023-06-23 10:54:25 +02:00
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)),
2023-06-12 23:06:20 +02:00
'Korrektur des Warenkorbs')
];
2023-06-19 16:25:10 +02:00
Finance({super.key});
2023-06-12 23:06:20 +02:00
@override
Widget build(BuildContext context) {
initializeDateFormatting('de_DE');
2023-06-16 15:36:13 +02:00
return Scaffold(
appBar: AppBar(
2023-06-19 19:37:06 +02:00
toolbarHeight: 75,
title: const Card(
child: ListTile(
leading: Icon(
Icons.euro,
2023-06-16 15:36:13 +02:00
),
2023-06-19 19:37:06 +02:00
title: Text(
'Aktuelles Guthaben:',
2023-06-16 15:36:13 +02:00
),
2023-06-19 19:37:06 +02:00
subtitle: Text(
'-00,34€',
)),
),
),
body: ListView.builder(
itemCount: null,
itemBuilder: (context, index) {
if (index < transactions.length) {
return Card(
child: ListTile(
2023-06-23 10:54:25 +02:00
leading: getIcon(transactions[index].type),
title: Text(gettitle(transactions[index].type)),
2023-06-19 19:37:06 +02:00
subtitle: getSubtitle(index),
2023-06-23 10:54:25 +02:00
trailing: transactions[index].type == Type.einkauf
2023-06-19 19:37:06 +02:00
? PopupMenuButton(
onSelected: (value) {},
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'Option',
child: ListTile(
leading: Icon(Icons.manage_history),
title: Text('Warenkorb bearbeiten')),
),
const PopupMenuItem<String>(
value: 'Option',
child: ListTile(
leading:
Icon(Icons.remove_shopping_cart),
title: Text('Einkauf stornieren')),
),
],
)
: null,
onTap: () {
2023-06-23 10:54:25 +02:00
if (transactions[index].type == Type.einkauf) {
2023-06-19 19:37:06 +02:00
showBottomSheet(
context: context,
builder: (BuildContext context) {
2023-06-23 10:54:25 +02:00
return ShowBasket();
2023-06-19 19:37:06 +02:00
});
}
}));
} else {
return null;
}
}));
}
2023-06-23 10:54:25 +02:00
String gettitle(Type art) {
2023-06-19 19:37:06 +02:00
switch (art) {
2023-06-23 10:54:25 +02:00
case Type.aufladung:
2023-06-19 19:37:06 +02:00
return 'Aufladung';
2023-06-23 10:54:25 +02:00
case Type.einkauf:
2023-06-19 19:37:06 +02:00
return 'Einkauf';
2023-06-23 10:54:25 +02:00
case Type.korrektur:
2023-06-19 19:37:06 +02:00
return 'Korrektur';
2023-06-23 10:54:25 +02:00
case Type.monatlBeitrag:
2023-06-19 19:37:06 +02:00
return 'monatlicher Beitrag';
}
}
Text getSubtitle(int index) {
2023-06-23 10:54:25 +02:00
String text = '${transactions[index].amount / 100}';
2023-06-19 19:37:06 +02:00
text += '';
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
2023-06-23 10:54:25 +02:00
.format(transactions[index].date);
if (transactions[index].description != null) {
(text += '\n${transactions[index].description}');
2023-06-19 19:37:06 +02:00
}
return Text(text);
}
2023-06-23 10:54:25 +02:00
Icon getIcon(Type art) {
2023-06-19 19:37:06 +02:00
switch (art) {
2023-06-23 10:54:25 +02:00
case Type.aufladung:
2023-06-19 19:37:06 +02:00
return const Icon(Icons.savings);
2023-06-23 10:54:25 +02:00
case Type.einkauf:
2023-06-19 19:37:06 +02:00
return const Icon(Icons.shopping_basket);
2023-06-23 10:54:25 +02:00
case Type.korrektur:
2023-06-19 19:37:06 +02:00
return const Icon(Icons.priority_high);
2023-06-23 10:54:25 +02:00
case Type.monatlBeitrag:
2023-06-19 19:37:06 +02:00
return const Icon(Icons.payment);
}
2023-06-12 23:06:20 +02:00
}
}