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