Mitgliederladen/Frontend-user/lib/basket.dart

104 lines
3 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
2023-06-25 19:10:29 +02:00
- editing
2023-06-23 10:54:25 +02:00
*/
class ShowBasket extends StatelessWidget {
2023-06-25 18:11:26 +02:00
final int index;
2023-06-25 15:11:23 +02:00
final bool editable;
2023-06-25 18:11:26 +02:00
const ShowBasket(this.index, {this.editable = false, super.key});
2023-06-23 10:54:25 +02:00
@override
Widget build(BuildContext context) {
2023-06-25 18:11:26 +02:00
final List<Basket> basket = SampleData().transactions[index].basket!;
return Column(
children: [
Expanded(
child: getBasket(basket),
),
const Divider(),
ListTile(
2023-06-25 15:11:23 +02:00
leading: const Icon(
Icons.euro,
),
title: const Text(
'Kosten:',
),
subtitle: Text(
2023-06-25 18:11:26 +02:00
'${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),
],
);
2023-06-25 15:11:23 +02:00
}
ListView getBasket(List<Basket> basket) {
2023-06-23 10:54:25 +02:00
return ListView.builder(
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 18:11:26 +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
? SizedBox(
width: 100,
child: TextField(
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
]),
)
: 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:
2023-06-25 19:10:29 +02:00
return const Text("🍒");
2023-06-25 15:11:23 +02:00
case Category.brotCerealienUndAufstriche:
2023-06-25 18:11:26 +02:00
return const Text(
'🍞',
style: TextStyle(fontSize: 24),
);
2023-06-25 15:11:23 +02:00
case Category.drogerieUndHaushalt:
case Category.getraenke:
case Category.kochenUndBacken:
case Category.pfand:
case Category.suessesUndKnabbereien:
case Category.oeleSossenUndGewuerze:
default:
return const Icon(Icons.error);
}
}
2023-06-23 10:54:25 +02:00
}