Mitgliederladen/Frontend-user/lib/finance.dart

126 lines
4.3 KiB
Dart
Raw Permalink 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-23 13:03:17 +02:00
import 'sample_data.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-19 16:25:10 +02:00
class Finance extends StatelessWidget {
2023-06-23 13:03:17 +02:00
const Finance({super.key});
2023-06-19 16:25:10 +02:00
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) {
2023-06-23 13:03:17 +02:00
if (index < SampleData().transactions.length) {
2023-06-19 19:37:06 +02:00
return Card(
child: ListTile(
2023-06-23 13:03:17 +02:00
leading: getIcon(SampleData().transactions[index].type),
title: Text(
gettitle(SampleData().transactions[index].type)),
2023-06-19 19:37:06 +02:00
subtitle: getSubtitle(index),
2023-06-23 13:03:17 +02:00
trailing: SampleData().transactions[index].type ==
TransaktionArt.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 13:03:17 +02:00
if (SampleData().transactions[index].type ==
TransaktionArt.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 13:03:17 +02:00
String gettitle(TransaktionArt art) {
2023-06-19 19:37:06 +02:00
switch (art) {
2023-06-23 13:03:17 +02:00
case TransaktionArt.aufladung:
2023-06-19 19:37:06 +02:00
return 'Aufladung';
2023-06-23 13:03:17 +02:00
case TransaktionArt.einkauf:
2023-06-19 19:37:06 +02:00
return 'Einkauf';
2023-06-23 13:03:17 +02:00
case TransaktionArt.korrektur:
2023-06-19 19:37:06 +02:00
return 'Korrektur';
2023-06-23 13:03:17 +02:00
case TransaktionArt.monatlBeitrag:
2023-06-19 19:37:06 +02:00
return 'monatlicher Beitrag';
}
}
Text getSubtitle(int index) {
2023-06-23 13:03:17 +02:00
String text = '${SampleData().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 13:03:17 +02:00
.format(SampleData().transactions[index].date);
if (SampleData().transactions[index].description != null) {
(text += '\n${SampleData().transactions[index].description}');
2023-06-19 19:37:06 +02:00
}
return Text(text);
}
2023-06-23 13:03:17 +02:00
Icon getIcon(TransaktionArt art) {
2023-06-19 19:37:06 +02:00
switch (art) {
2023-06-23 13:03:17 +02:00
case TransaktionArt.aufladung:
2023-06-19 19:37:06 +02:00
return const Icon(Icons.savings);
2023-06-23 13:03:17 +02:00
case TransaktionArt.einkauf:
2023-06-19 19:37:06 +02:00
return const Icon(Icons.shopping_basket);
2023-06-23 13:03:17 +02:00
case TransaktionArt.korrektur:
2023-06-19 19:37:06 +02:00
return const Icon(Icons.priority_high);
2023-06-23 13:03:17 +02:00
case TransaktionArt.monatlBeitrag:
2023-06-19 19:37:06 +02:00
return const Icon(Icons.payment);
}
2023-06-12 23:06:20 +02:00
}
}