Compare commits
No commits in common. "4da346f6d74fb2fd48d75b0a85f0b214c8ce438c" and "7c9d449c63f84f58137c967f134576aac57737a5" have entirely different histories.
4da346f6d7
...
7c9d449c63
4 changed files with 53 additions and 140 deletions
|
@ -1,78 +1,30 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'sample_data.dart';
|
||||
|
||||
/* todo:
|
||||
- Flag für Ansicht/Bearbeitung
|
||||
- individuelle Icons je nach Kategorie
|
||||
- Gesamtpreis
|
||||
*/
|
||||
|
||||
class ShowBasket extends StatelessWidget {
|
||||
final int index;
|
||||
final bool editable;
|
||||
const ShowBasket(this.index, {this.editable = false, super.key});
|
||||
final Transaction transaction;
|
||||
|
||||
const ShowBasket({super.key, required this.transaction});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final List<Basket> basket = SampleData().transactions[index].basket!;
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: getBasket(basket),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
leading: const Icon(
|
||||
Icons.euro,
|
||||
),
|
||||
title: const Text(
|
||||
'Kosten:',
|
||||
),
|
||||
subtitle: Text(
|
||||
'${SampleData().transactions[index].amount / 100}',
|
||||
),
|
||||
trailing: editable
|
||||
? Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FloatingActionButton(
|
||||
backgroundColor: Colors.redAccent.shade100,
|
||||
child: const Icon(Icons.delete),
|
||||
onPressed: () {}),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
FloatingActionButton(
|
||||
child: const Icon(Icons.shopping_cart_checkout),
|
||||
onPressed: () {}),
|
||||
],
|
||||
)
|
||||
: null),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
ListView getBasket(List<Basket> basket) {
|
||||
return ListView.builder(
|
||||
itemCount: null,
|
||||
itemBuilder: (context, index) {
|
||||
if (index < basket.length) {
|
||||
if (index < transaction.basket!.length) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: getLeading(basket[index].products.category),
|
||||
title: Text(basket[index].products.name),
|
||||
subtitle: Text(
|
||||
'${basket[index].amount} ${basket[index].products.unit}'),
|
||||
trailing: editable
|
||||
? SizedBox(
|
||||
width: 100,
|
||||
child: TextField(
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: <TextInputFormatter>[
|
||||
FilteringTextInputFormatter.digitsOnly
|
||||
]),
|
||||
)
|
||||
: null),
|
||||
leading: const Icon(Icons.abc),
|
||||
title: Text(
|
||||
transaction.basket![index].products.name), //better null check
|
||||
//trailing: Text(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -80,24 +32,4 @@ class ShowBasket extends StatelessWidget {
|
|||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget getLeading(Category category) {
|
||||
switch (category) {
|
||||
case Category.obstUndGemuese:
|
||||
return const Text("🍅");
|
||||
case Category.brotCerealienUndAufstriche:
|
||||
return const Text(
|
||||
'🍞',
|
||||
style: TextStyle(fontSize: 24),
|
||||
);
|
||||
case Category.drogerieUndHaushalt:
|
||||
case Category.getraenke:
|
||||
case Category.kochenUndBacken:
|
||||
case Category.pfand:
|
||||
case Category.suessesUndKnabbereien:
|
||||
case Category.oeleSossenUndGewuerze:
|
||||
default:
|
||||
return const Icon(Icons.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ todo:
|
|||
- farbliche Hervorhebungen
|
||||
- semanticLabels, Screenreader
|
||||
- monatliche Aufladung: ausstehende Beträge
|
||||
- Icons: maybe flutter awesome
|
||||
*/
|
||||
|
||||
class Finance extends StatelessWidget {
|
||||
|
@ -46,17 +45,40 @@ class Finance extends StatelessWidget {
|
|||
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));
|
||||
subtitle: getSubtitle(index),
|
||||
trailing: SampleData().transactions[index].type ==
|
||||
TransaktionArt.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 (SampleData().transactions[index].basket != null) {
|
||||
showBottomSheet(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ShowBasket(
|
||||
transaction:
|
||||
SampleData().transactions[index]);
|
||||
});
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -72,19 +94,17 @@ class Finance extends StatelessWidget {
|
|||
case TransaktionArt.korrektur:
|
||||
return 'Korrektur';
|
||||
case TransaktionArt.monatlBeitrag:
|
||||
return 'Monatlicher Beitrag';
|
||||
default:
|
||||
return 'Ein Error ist aufgetreten';
|
||||
return 'monatlicher Beitrag';
|
||||
}
|
||||
}
|
||||
|
||||
Text getSubtitle(Transaction transaction) {
|
||||
String text = '${transaction.amount / 100}';
|
||||
Text getSubtitle(int index) {
|
||||
String text = '${SampleData().transactions[index].amount / 100}';
|
||||
text += '€ ';
|
||||
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
|
||||
.format(transaction.date);
|
||||
if (transaction.description != null) {
|
||||
(text += '\n${transaction.description}');
|
||||
.format(SampleData().transactions[index].date);
|
||||
if (SampleData().transactions[index].description != null) {
|
||||
(text += '\n${SampleData().transactions[index].description}');
|
||||
}
|
||||
|
||||
return Text(text);
|
||||
|
@ -96,42 +116,10 @@ class Finance extends StatelessWidget {
|
|||
return const Icon(Icons.savings);
|
||||
case TransaktionArt.einkauf:
|
||||
return const Icon(Icons.shopping_basket);
|
||||
case TransaktionArt.korrektur:
|
||||
return const Icon(Icons.priority_high);
|
||||
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) => <PopupMenuEntry<String>>[
|
||||
const PopupMenuItem<String>(
|
||||
value: 'edit',
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.manage_history),
|
||||
title: Text('Warenkorb bearbeiten')),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'delete',
|
||||
child: ListTile(
|
||||
leading: Icon(Icons.remove_shopping_cart),
|
||||
title: Text('Einkauf stornieren')),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class MyApp extends StatelessWidget {
|
|||
brightness: Brightness.dark,
|
||||
seedColor: const Color(0xff5f7c61),
|
||||
)),
|
||||
themeMode: ThemeMode.system,
|
||||
themeMode: ThemeMode.dark,
|
||||
home: const MyHomePage(),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -59,13 +59,6 @@ class SampleData {
|
|||
];
|
||||
|
||||
static List<Basket> basket = [
|
||||
Basket(products[0], 20),
|
||||
Basket(products[1], 2200),
|
||||
Basket(products[2], 2),
|
||||
Basket(products[3], 1),
|
||||
Basket(products[4], 1),
|
||||
Basket(products[5], 2),
|
||||
Basket(products[6], 222),
|
||||
Basket(products[0], 20),
|
||||
Basket(products[1], 2200),
|
||||
Basket(products[2], 2),
|
||||
|
|
Loading…
Reference in a new issue