Mitgliederladen/Frontend-user/lib/finance.dart

110 lines
3.3 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-23 13:03:17 +02:00
import 'sample_data.dart';
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-27 00:48:14 +02:00
Intl.defaultLocale = 'de_DE';
2023-06-12 23:06:20 +02:00
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: SampleData().transactions.length,
2023-06-19 19:37:06 +02:00
itemBuilder: (context, index) {
return Card(
child: ListTile(
leading: getIcon(SampleData().transactions[index].type),
title:
Text(gettitle(SampleData().transactions[index].type)),
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
}));
}
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 += '';
2023-06-27 00:48:14 +02:00
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm")
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 IconButton(
icon: const Icon(Icons.manage_history),
onPressed: () {
showBottomSheet(
context: context,
builder: (BuildContext context) {
return ShowBasket(index, editable: true);
});
2023-06-25 18:11:26 +02:00
},
);
} else {
return null;
}
}
2023-06-12 23:06:20 +02:00
}