|
| 1 | +import 'package:eat_somewhere/data/foodentry.dart'; |
| 2 | +import 'package:eat_somewhere/data/helper.dart'; |
| 3 | +import 'package:eat_somewhere/widgets/chips/price_chip.dart'; |
| 4 | +import 'package:eat_somewhere/widgets/constrained_container.dart'; |
| 5 | +import 'package:flutter/material.dart'; |
| 6 | + |
| 7 | +class ShoppingListScreen extends StatefulWidget { |
| 8 | + final FoodEntry foodEntry; |
| 9 | + |
| 10 | + const ShoppingListScreen({Key? key, required this.foodEntry}) |
| 11 | + : super(key: key); |
| 12 | + |
| 13 | + @override |
| 14 | + State<ShoppingListScreen> createState() => _ShoppingListScreenState(); |
| 15 | +} |
| 16 | + |
| 17 | +class _ShoppingListScreenState extends State<ShoppingListScreen> { |
| 18 | + @override |
| 19 | + Widget build(BuildContext context) { |
| 20 | + return Scaffold( |
| 21 | + appBar: AppBar( |
| 22 | + title: const Text("Shopping List"), |
| 23 | + ), |
| 24 | + body: ConstrainedContainer(child: ListView( |
| 25 | + children: [ |
| 26 | + ListTile( |
| 27 | + title: Text(widget.foodEntry.food?.name ?? "Unknown"), |
| 28 | + subtitle: Text( |
| 29 | + "Price: ${PriceHelper.formatPriceWithUnit(widget.foodEntry.getEstimatedCost())}"), |
| 30 | + ), |
| 31 | + // Adjust the table to use the minimum width it needs |
| 32 | + Row( |
| 33 | + children: [ |
| 34 | + Expanded(child: Container(child: Table( |
| 35 | + defaultVerticalAlignment: TableCellVerticalAlignment.middle, |
| 36 | + children: [ |
| 37 | + ...widget.foodEntry |
| 38 | + .getShoppingList() |
| 39 | + .map((item) => TableRow( |
| 40 | + children: [ |
| 41 | + Text(item.amount.toString()), |
| 42 | + Text(item.ingredient?.unit.name ?? "Unknown"), |
| 43 | + Text(item.ingredient?.name ?? "Unknown"), |
| 44 | + PriceChip(amount: item.getEstimatedCost()), |
| 45 | + ])), |
| 46 | + ], |
| 47 | + ))) |
| 48 | + ], |
| 49 | + ) |
| 50 | + ], |
| 51 | + ), |
| 52 | + )); |
| 53 | + } |
| 54 | +} |
0 commit comments