forked from mgl_crew/Mitgliederladen
added prototype for editing baskets
This commit is contained in:
parent
0ee26fedb0
commit
4da346f6d7
3 changed files with 105 additions and 70 deletions
|
@ -8,17 +8,20 @@ import 'sample_data.dart';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ShowBasket extends StatelessWidget {
|
class ShowBasket extends StatelessWidget {
|
||||||
final Transaction transaction;
|
final int index;
|
||||||
final bool editable;
|
final bool editable;
|
||||||
|
const ShowBasket(this.index, {this.editable = false, super.key});
|
||||||
const ShowBasket(
|
|
||||||
{super.key, required this.transaction, this.editable = false});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(children: [
|
final List<Basket> basket = SampleData().transactions[index].basket!;
|
||||||
Card(
|
return Column(
|
||||||
child: ListTile(
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: getBasket(basket),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
ListTile(
|
||||||
leading: const Icon(
|
leading: const Icon(
|
||||||
Icons.euro,
|
Icons.euro,
|
||||||
),
|
),
|
||||||
|
@ -26,27 +29,50 @@ class ShowBasket extends StatelessWidget {
|
||||||
'Kosten:',
|
'Kosten:',
|
||||||
),
|
),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'${transaction.amount / 100}',
|
'${SampleData().transactions[index].amount / 100}',
|
||||||
)),
|
),
|
||||||
),
|
trailing: editable
|
||||||
getBasket(transaction.basket!)
|
? 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) {
|
ListView getBasket(List<Basket> basket) {
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
shrinkWrap: true,
|
|
||||||
itemCount: null,
|
itemCount: null,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
if (index < basket.length) {
|
if (index < basket.length) {
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: getLeading(basket[index].products.category),
|
leading: getLeading(basket[index].products.category),
|
||||||
title: Text(basket[index].products.name),
|
title: Text(basket[index].products.name),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'${basket[index].amount} ${basket[index].products.unit}'),
|
'${basket[index].amount} ${basket[index].products.unit}'),
|
||||||
trailing: editable == true ? getTrailing() : null,
|
trailing: editable
|
||||||
),
|
? SizedBox(
|
||||||
|
width: 100,
|
||||||
|
child: TextField(
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
inputFormatters: <TextInputFormatter>[
|
||||||
|
FilteringTextInputFormatter.digitsOnly
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
: null),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -60,7 +86,10 @@ class ShowBasket extends StatelessWidget {
|
||||||
case Category.obstUndGemuese:
|
case Category.obstUndGemuese:
|
||||||
return const Text("🍅");
|
return const Text("🍅");
|
||||||
case Category.brotCerealienUndAufstriche:
|
case Category.brotCerealienUndAufstriche:
|
||||||
return const Text('🍞');
|
return const Text(
|
||||||
|
'🍞',
|
||||||
|
style: TextStyle(fontSize: 24),
|
||||||
|
);
|
||||||
case Category.drogerieUndHaushalt:
|
case Category.drogerieUndHaushalt:
|
||||||
case Category.getraenke:
|
case Category.getraenke:
|
||||||
case Category.kochenUndBacken:
|
case Category.kochenUndBacken:
|
||||||
|
@ -71,14 +100,4 @@ class ShowBasket extends StatelessWidget {
|
||||||
return const Icon(Icons.error);
|
return const Icon(Icons.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getTrailing() {
|
|
||||||
return TextField(
|
|
||||||
decoration: const InputDecoration(labelText: "Enter your number"),
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
inputFormatters: <TextInputFormatter>[
|
|
||||||
FilteringTextInputFormatter.digitsOnly
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,40 +46,17 @@ class Finance extends StatelessWidget {
|
||||||
leading: getIcon(SampleData().transactions[index].type),
|
leading: getIcon(SampleData().transactions[index].type),
|
||||||
title: Text(
|
title: Text(
|
||||||
gettitle(SampleData().transactions[index].type)),
|
gettitle(SampleData().transactions[index].type)),
|
||||||
subtitle: getSubtitle(index),
|
subtitle: getSubtitle(SampleData().transactions[index]),
|
||||||
trailing: SampleData().transactions[index].type ==
|
trailing: getTrailing(context, index),
|
||||||
TransaktionArt.einkauf
|
onTap: (SampleData().transactions[index].basket != null)
|
||||||
? PopupMenuButton(
|
? () {
|
||||||
onSelected: (value) {},
|
showBottomSheet(
|
||||||
itemBuilder: (BuildContext context) =>
|
context: context,
|
||||||
<PopupMenuEntry<String>>[
|
builder: (BuildContext context) {
|
||||||
const PopupMenuItem<String>(
|
return ShowBasket(index);
|
||||||
value: 'Option',
|
});
|
||||||
child: ListTile(
|
}
|
||||||
leading: Icon(Icons.manage_history),
|
: null));
|
||||||
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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -95,19 +72,19 @@ class Finance extends StatelessWidget {
|
||||||
case TransaktionArt.korrektur:
|
case TransaktionArt.korrektur:
|
||||||
return 'Korrektur';
|
return 'Korrektur';
|
||||||
case TransaktionArt.monatlBeitrag:
|
case TransaktionArt.monatlBeitrag:
|
||||||
return 'monatlicher Beitrag';
|
return 'Monatlicher Beitrag';
|
||||||
default:
|
default:
|
||||||
return 'Ein Error ist aufgetreten';
|
return 'Ein Error ist aufgetreten';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text getSubtitle(int index) {
|
Text getSubtitle(Transaction transaction) {
|
||||||
String text = '${SampleData().transactions[index].amount / 100}';
|
String text = '${transaction.amount / 100}';
|
||||||
text += '€ ';
|
text += '€ ';
|
||||||
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
|
text += DateFormat("EEEE, dd. MMMM yyyy HH:mm", 'de_DE')
|
||||||
.format(SampleData().transactions[index].date);
|
.format(transaction.date);
|
||||||
if (SampleData().transactions[index].description != null) {
|
if (transaction.description != null) {
|
||||||
(text += '\n${SampleData().transactions[index].description}');
|
(text += '\n${transaction.description}');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Text(text);
|
return Text(text);
|
||||||
|
@ -125,4 +102,36 @@ class Finance extends StatelessWidget {
|
||||||
return const Icon(Icons.priority_high);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,13 @@ class SampleData {
|
||||||
];
|
];
|
||||||
|
|
||||||
static List<Basket> basket = [
|
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[0], 20),
|
||||||
Basket(products[1], 2200),
|
Basket(products[1], 2200),
|
||||||
Basket(products[2], 2),
|
Basket(products[2], 2),
|
||||||
|
|
Loading…
Reference in a new issue