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'; class Finance extends StatelessWidget { const Finance({super.key}); @override Widget build(BuildContext context) { initializeDateFormatting('de_DE'); Intl.defaultLocale = '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: SampleData().transactions.length, 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(SampleData() .transactions[index] .basket!); }); } : 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").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 IconButton( icon: const Icon(Icons.manage_history), onPressed: () { showBottomSheet( context: context, builder: (BuildContext context) { return ShowBasket(SampleData().transactions[index].basket!, editable: true); }); }, ); } else { return null; } } }