103 lines
3 KiB
Dart
103 lines
3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'sample_data.dart';
|
|
|
|
/* todo:
|
|
- 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});
|
|
|
|
@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) {
|
|
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),
|
|
);
|
|
} else {
|
|
return null;
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|