Skip to content

Commit 2dd3c89

Browse files
committed
Start on shopping list
1 parent ead4ca7 commit 2dd3c89

7 files changed

Lines changed: 97 additions & 4 deletions

File tree

EatSomewhere/Server/UserManagementServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class UserManagementServer
1010
{
1111
public static User? GetUserBySession(ServerRequest request)
1212
{
13-
string? session = null;
13+
string? session;
1414
string? authorizationHeader = request.context.Request.Headers.Get("Authorization");
1515
if(authorizationHeader != null)
1616
{

app/lib/data/foodentry.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ class FoodEntry {
7272
return (cost / getPersonCount()).ceil();
7373
}
7474

75+
List<IngredientEntry> getShoppingList() {
76+
List<IngredientEntry> shoppingList = [];
77+
int persons = getPersonCount();
78+
if(food == null) return [];
79+
for (IngredientEntry ingredient in food!.ingredients) {
80+
print("Ingredient: ${ingredient.ingredient}");
81+
if(ingredient.ingredient == null) continue;
82+
IngredientEntry shoppingItem = IngredientEntry.fromIngredient(ingredient.ingredient!);
83+
shoppingItem.amount = ingredient.amount / (food?.personCount ?? 1) * persons;
84+
shoppingList.add(shoppingItem);
85+
}
86+
return shoppingList;
87+
}
88+
7589
FoodEntry.fromFood(Food this.food);
7690
}
7791

app/lib/screens/create_food_entry_screen.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:eat_somewhere/data/food.dart';
33
import 'package:eat_somewhere/data/foodentry.dart';
44
import 'package:eat_somewhere/data/helper.dart';
55
import 'package:eat_somewhere/screens/select_food.dart';
6+
import 'package:eat_somewhere/screens/shopping_list_screen.dart';
67
import 'package:eat_somewhere/service/storage.dart';
78
import 'package:eat_somewhere/widgets/chips/additional_persons_chip.dart';
89
import 'package:eat_somewhere/widgets/chips/chip_combiner.dart';
@@ -203,6 +204,16 @@ class _CreateFoodEntryScreenState extends State<CreateFoodEntryScreen> {
203204
}
204205
},
205206
child: const Text("Add Participant")),
207+
FilledButton(onPressed: () {
208+
Navigator.push(
209+
context,
210+
MaterialPageRoute(
211+
builder: (context) => ShoppingListScreen(
212+
foodEntry: widget.foodEntry
213+
),
214+
),
215+
);
216+
}, child: Text("Show shopping list")),
206217
TextField(
207218
decoration: InputDecoration(
208219
labelText: "Comment",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

app/lib/service/storage.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class Storage {
117117
}
118118
static Future reloadFoodEntries() async {
119119
instance.foodEntries[getSettings().chosenAssembly] = await ServerLoader.LoadFoodEntries(0, 20);
120+
instance.foodEntries[getSettings().chosenAssembly]!.sort((x,y) => y.date.compareTo(x.date));
120121
onDataReload();
121122
}
122123

app/lib/widgets/chips/additional_persons_chip.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ class AdditionalPersonsChip extends CombinableChip {
1515
@override
1616
Widget build(BuildContext context) {
1717
return Chip(
18-
label: Row(
18+
label: SizedBox(
19+
width: 55,
20+
child: Row(
1921
spacing: 6,
22+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
2023
children: [
2124
Text(
2225
"+$additionalPersons",
@@ -25,6 +28,7 @@ class AdditionalPersonsChip extends CombinableChip {
2528
Icon(Icons.group, color: UserColors.getContrastColor(user),)
2629
],
2730
),
31+
),
2832
shape: this.shape,
2933
backgroundColor: UserColors.getColor(user),
3034
padding: const EdgeInsets.all(0),

app/lib/widgets/chips/arrow_price_chip.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ class ArrowPriceChip extends CombinableChip {
1414
return InkWell(
1515
onTap: onTap,
1616
child: Chip(
17-
label: Text(
18-
"→ ${PriceHelper.formatPriceWithUnit(amount)} →"
17+
label: SizedBox(
18+
width: 90,
19+
child: Row(
20+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
21+
children: [
22+
Text("→",),
23+
Text(
24+
PriceHelper.formatPriceWithUnit(amount)),
25+
Text("→",),
26+
],
27+
),
1928
),
2029
shape: shape,
2130
padding: const EdgeInsets.all(0),

0 commit comments

Comments
 (0)