import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:intl/date_symbol_data_local.dart'; import 'basket.dart'; import 'sample_data.dart'; /* todo: - Einkauf und Settings - Warenkorb - farbliche Hervorhebungen - semanticLabels, Screenreader - monatliche Aufladung: ausstehende Beträge - Icons: maybe flutter awesome */ class Finance extends StatelessWidget { const 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 < SampleData().transactions.length) { 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)); } else { return null; } })); } String gettitle(TransaktionArt art) { switch (art) { case TransaktionArt.aufladung: return 'Aufladung'; case TransaktionArt.einkauf: return 'Einkauf'; case TransaktionArt.korrektur: return 'Korrektur'; case TransaktionArt.monatlBeitrag: return 'Monatlicher Beitrag'; default: return 'Ein Error ist aufgetreten'; } } Text getSubtitle(Transaction transaction) { String text = '${transaction.amount / 100}'; text += '€ '; text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE') .format(transaction.date); if (transaction.description != null) { (text += '\n${transaction.description}'); } return Text(text); } Icon getIcon(TransaktionArt art) { switch (art) { case TransaktionArt.aufladung: return const Icon(Icons.savings); case TransaktionArt.einkauf: return const Icon(Icons.shopping_basket); case TransaktionArt.monatlBeitrag: return const Icon(Icons.payment); default: return const Icon(Icons.priority_high); } } 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) => >[ const PopupMenuItem( value: 'edit', child: ListTile( leading: Icon(Icons.manage_history), title: Text('Warenkorb bearbeiten')), ), const PopupMenuItem( value: 'delete', child: ListTile( leading: Icon(Icons.remove_shopping_cart), title: Text('Einkauf stornieren')), ), ], ); } else { return null; } } }