Mitgliederladen/Frontend-user/lib/basket.dart

85 lines
2.2 KiB
Dart
Raw Normal View History

2023-06-23 10:54:25 +02:00
import 'package:flutter/material.dart';
2023-06-25 15:11:23 +02:00
import 'package:flutter/services.dart';
2023-06-23 13:03:17 +02:00
import 'sample_data.dart';
2023-06-23 10:54:25 +02:00
/* todo:
- individuelle Icons je nach Kategorie
- Gesamtpreis
*/
class ShowBasket extends StatelessWidget {
2023-06-25 12:04:17 +02:00
final Transaction transaction;
2023-06-25 15:11:23 +02:00
final bool editable;
2023-06-25 12:04:17 +02:00
2023-06-25 15:11:23 +02:00
const ShowBasket(
{super.key, required this.transaction, this.editable = false});
2023-06-23 10:54:25 +02:00
@override
Widget build(BuildContext context) {
2023-06-25 15:11:23 +02:00
return Column(children: [
Card(
child: ListTile(
leading: const Icon(
Icons.euro,
),
title: const Text(
'Kosten:',
),
subtitle: Text(
'${transaction.amount / 100}',
)),
),
getBasket(transaction.basket!)
]);
}
ListView getBasket(List<Basket> basket) {
2023-06-23 10:54:25 +02:00
return ListView.builder(
2023-06-25 15:11:23 +02:00
shrinkWrap: true,
2023-06-23 10:54:25 +02:00
itemCount: null,
itemBuilder: (context, index) {
2023-06-25 15:11:23 +02:00
if (index < basket.length) {
2023-06-23 10:54:25 +02:00
return Card(
child: ListTile(
2023-06-25 15:11:23 +02:00
leading: getLeading(basket[index].products.category),
title: Text(basket[index].products.name),
subtitle: Text(
'${basket[index].amount} ${basket[index].products.unit}'),
trailing: editable == true ? getTrailing() : null,
2023-06-23 10:54:25 +02:00
),
);
} else {
return null;
}
},
);
}
2023-06-25 15:11:23 +02:00
Widget getLeading(Category category) {
switch (category) {
case Category.obstUndGemuese:
return const Text("🍅");
case Category.brotCerealienUndAufstriche:
return const Text('🍞');
case Category.drogerieUndHaushalt:
case Category.getraenke:
case Category.kochenUndBacken:
case Category.pfand:
case Category.suessesUndKnabbereien:
case Category.oeleSossenUndGewuerze:
default:
return const Icon(Icons.error);
}
}
Widget getTrailing() {
return TextField(
decoration: const InputDecoration(labelText: "Enter your number"),
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
],
);
}
2023-06-23 10:54:25 +02:00
}