Mitgliederladen/Frontend-user/lib/basket.dart

77 lines
2.4 KiB
Dart
Raw Permalink 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
class ShowBasket extends StatelessWidget {
2023-07-04 22:07:00 +02:00
final Basket basket;
2023-06-25 15:11:23 +02:00
final bool editable;
2023-07-04 22:07:00 +02:00
const ShowBasket(this.basket, {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
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-07-04 22:07:00 +02:00
'${basket.price}',
2023-06-25 18:11:26 +02:00
),
trailing: editable
? Row(
mainAxisSize: MainAxisSize.min,
children: [
FloatingActionButton(
backgroundColor: Colors.redAccent.shade100,
child: const Icon(Icons.remove_shopping_cart),
2023-06-25 18:11:26 +02:00
onPressed: () {}),
const SizedBox(
width: 10,
),
FloatingActionButton(
child: const Icon(Icons.shopping_cart_checkout),
onPressed: () {}),
],
)
: null),
],
);
2023-06-25 15:11:23 +02:00
}
2023-07-04 22:07:00 +02:00
ListView getBasket(Basket basket) {
2023-06-23 10:54:25 +02:00
return ListView.builder(
2023-07-04 22:07:00 +02:00
itemCount: basket.purchases.length,
2023-06-23 10:54:25 +02:00
itemBuilder: (context, index) {
return Card(
child: ListTile(
leading: Text(
2023-07-04 22:07:00 +02:00
basket.purchases.keys.elementAt(index).category.icon,
style: const TextStyle(fontSize: 24),
),
2023-07-04 22:07:00 +02:00
title: Text(basket.purchases.keys.elementAt(index).name),
subtitle: Text(
2023-07-04 22:07:00 +02:00
'${basket.purchases.values.elementAt(index)} ${basket.purchases.keys.elementAt(index).unit}'),
trailing: editable
? SizedBox(
width: 100,
child: TextField(
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
]),
)
: null),
);
2023-06-23 10:54:25 +02:00
},
);
}
}