Mitgliederladen/Frontend-user/lib/finance.dart

149 lines
5.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-16 15:36:13 +02:00
import 'expand.dart';
2023-06-12 23:06:20 +02:00
/*
todo:
2023-06-19 11:21:54 +02:00
- Design, Darkmode
2023-06-16 15:36:13 +02:00
- Einkauf und Settings
- Details zum Warenkorb und Beschreibung (https://stackoverflow.com/questions/49029841/how-to-animate-collapse-elements-in-flutter)
2023-06-12 23:06:20 +02:00
- farbliche Hervorhebungen
*/
enum Art { monatlBeitrag, aufladung, einkauf, korrektur }
final now = DateTime.now();
class Transaction {
int betrag;
Art art;
DateTime datum;
String beschreibung;
2023-06-19 11:21:54 +02:00
bool elevated = false;
2023-06-12 23:06:20 +02:00
Transaction(this.art, this.betrag, this.datum, this.beschreibung);
}
2023-06-16 15:36:13 +02:00
class Finance extends StatefulWidget {
const Finance({super.key});
2023-06-12 23:06:20 +02:00
2023-06-16 15:36:13 +02:00
@override
State<Finance> createState() => _Finance();
}
2023-06-19 12:12:18 +02:00
//sample data
2023-06-16 15:36:13 +02:00
class _Finance extends State<Finance> {
2023-06-12 23:06:20 +02:00
final List<Transaction> transactions = [
Transaction(Art.monatlBeitrag, 0, now, ''),
Transaction(Art.aufladung, 2042, now, ''),
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2)), ''),
2023-06-16 15:36:13 +02:00
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
'Korrektur des Warenkorbs'),
Transaction(Art.monatlBeitrag, 0, now, ''),
Transaction(Art.aufladung, 2042, now, ''),
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2)), ''),
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
'Korrektur des Warenkorbs'),
Transaction(Art.monatlBeitrag, 0, now, ''),
Transaction(Art.aufladung, 2042, now, ''),
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2)), ''),
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
'Korrektur des Warenkorbs'),
Transaction(Art.monatlBeitrag, 0, now, ''),
Transaction(Art.aufladung, 2042, now, ''),
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2)), ''),
2023-06-19 12:12:18 +02:00
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
'Korrektur des Warenkorbs'),
Transaction(Art.monatlBeitrag, 0, now, ''),
Transaction(Art.aufladung, 2042, now, ''),
Transaction(Art.einkauf, -2442, now.subtract(const Duration(days: 2)), ''),
2023-06-12 23:06:20 +02:00
Transaction(Art.korrektur, 2332, now.subtract(const Duration(hours: 5)),
'Korrektur des Warenkorbs')
];
@override
Widget build(BuildContext context) {
initializeDateFormatting('de_DE');
2023-06-16 15:36:13 +02:00
return Scaffold(
appBar: AppBar(
toolbarHeight: 75,
title: const Card(
child: Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(
Icons.euro,
//color: Colors.black,
//semanticLabel: 'Text for screenreader',
),
Column(
children: [
Text(
'Aktuelles Guthaben:',
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
'-00,34€',
style: TextStyle(fontWeight: FontWeight.bold),
)
],
)
],
),
2023-06-12 23:06:20 +02:00
),
2023-06-16 15:36:13 +02:00
)),
body: ListView.builder(
itemCount: null,
itemBuilder: (context, index) {
if (index < transactions.length) {
return Card(
clipBehavior: Clip.hardEdge,
child: InkWell(
2023-06-19 11:21:54 +02:00
splashColor: const Color(0xff5f7c61).withAlpha(30),
2023-06-16 15:36:13 +02:00
onTap: () {
transactions[index].elevated =
!transactions[index].elevated;
setState(() {});
debugPrint('Card tapped');
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(transactions[index].art == Art.korrektur
? Icons.error
: Icons.money),
Column(
children: [
Row(
children: [
Text(DateFormat(
"EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
.format(now)),
Text(
'${transactions[index].art}: ${transactions[index].betrag / 100}'),
],
),
2023-06-19 12:12:18 +02:00
if (transactions[index].beschreibung != '')
Expand(
expand: transactions[index].elevated,
child: Text(transactions[index].beschreibung))
2023-06-16 15:36:13 +02:00
],
),
],
),
2023-06-12 23:06:20 +02:00
),
2023-06-16 15:36:13 +02:00
),
);
} else {
return null;
}
},
));
2023-06-12 23:06:20 +02:00
}
}