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
|
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-25 15:11:23 +02:00
|
|
|
- Icons: maybe flutter awesome
|
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-25 18:11:26 +02:00
|
|
|
subtitle: getSubtitle(SampleData().transactions[index]),
|
|
|
|
trailing: getTrailing(context, index),
|
|
|
|
onTap: (SampleData().transactions[index].basket != null)
|
|
|
|
? () {
|
|
|
|
showBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ShowBasket(index);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
: null));
|
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-25 18:11:26 +02:00
|
|
|
return 'Monatlicher Beitrag';
|
2023-06-25 15:11:23 +02:00
|
|
|
default:
|
|
|
|
return 'Ein Error ist aufgetreten';
|
2023-06-19 19:37:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-25 18:11:26 +02:00
|
|
|
Text getSubtitle(Transaction transaction) {
|
|
|
|
String text = '${transaction.amount / 100}';
|
2023-06-19 19:37:06 +02:00
|
|
|
text += '€ ';
|
|
|
|
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
|
2023-06-25 18:11:26 +02:00
|
|
|
.format(transaction.date);
|
|
|
|
if (transaction.description != null) {
|
|
|
|
(text += '\n${transaction.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.monatlBeitrag:
|
2023-06-19 19:37:06 +02:00
|
|
|
return const Icon(Icons.payment);
|
2023-06-25 15:11:23 +02:00
|
|
|
default:
|
|
|
|
return const Icon(Icons.priority_high);
|
2023-06-19 19:37:06 +02:00
|
|
|
}
|
2023-06-12 23:06:20 +02:00
|
|
|
}
|
2023-06-25 18:11:26 +02:00
|
|
|
|
|
|
|
getTrailing(BuildContext context, int index) {
|
|
|
|
if (SampleData().transactions[index].type == TransaktionArt.einkauf) {
|
|
|
|
return PopupMenuButton(
|
|
|
|
onSelected: (value) {
|
|
|
|
if (value == 'edit') {
|
|
|
|
showBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return ShowBasket(index, editable: true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
|
|
|
|
const PopupMenuItem<String>(
|
|
|
|
value: 'edit',
|
|
|
|
child: ListTile(
|
|
|
|
leading: Icon(Icons.manage_history),
|
|
|
|
title: Text('Warenkorb bearbeiten')),
|
|
|
|
),
|
|
|
|
const PopupMenuItem<String>(
|
|
|
|
value: 'delete',
|
|
|
|
child: ListTile(
|
|
|
|
leading: Icon(Icons.remove_shopping_cart),
|
|
|
|
title: Text('Einkauf stornieren')),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2023-06-12 23:06:20 +02:00
|
|
|
}
|