Skip to content

Commit 566c9eb

Browse files
RedX2501Guilherme Bufolo
andauthored
Feature/ask before deleting not empty list (#575)
Co-authored-by: Guilherme Bufolo <guibufolo+hobbyhimmel@gmail.com>
1 parent b89e0f3 commit 566c9eb

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

kitchenowl/lib/l10n/app_en.arb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@
294294
"@setupTitle": {},
295295
"@share": {},
296296
"@shoppingList": {},
297+
"@shoppingListContainsEntries": {
298+
"placeholders": {
299+
"entriesCount": {
300+
"type": "num"
301+
}
302+
}
303+
},
297304
"@shoppingListDelete": {},
298305
"@shoppingListDeleteConfirmation": {
299306
"placeholders": {
@@ -578,6 +585,7 @@
578585
"setupTitle": "Hey there! Ready to shop?",
579586
"share": "Share",
580587
"shoppingList": "Shopping list",
588+
"shoppingListContainsEntries": "{entriesCount, plural, =0{The shopping list contains no entrie(s).} =1{The shopping list contains 1 entry.} other{The shopping list contains {entriesCount} entries.}}",
581589
"shoppingListDelete": "Delete shopping list",
582590
"shoppingListDeleteConfirmation": "Are you sure you want to delete {shoppingList}?",
583591
"shoppingListEdit": "Edit shopping list",

kitchenowl/lib/pages/settings_household/household_settings_shoppinglist_page.dart

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ enum _ShoppinglistAction {
1414
class HouseholdSettingsShoppinglistPage extends StatelessWidget {
1515
const HouseholdSettingsShoppinglistPage({super.key});
1616

17+
static Future<bool> confirmDeleteShoppingList(
18+
BuildContext context, ShoppingList shoppinglist) async {
19+
return await askForConfirmation(
20+
context: context,
21+
title: Text(
22+
AppLocalizations.of(context)!.shoppingListDelete,
23+
),
24+
content: SingleChildScrollView(
25+
child: ListBody(
26+
children: [
27+
Text(
28+
AppLocalizations.of(context)!.shoppingListDeleteConfirmation(
29+
shoppinglist.name,
30+
),
31+
),
32+
if (shoppinglist.items.length > 0) const SizedBox(height: 20),
33+
if (shoppinglist.items.length > 0)
34+
Text(AppLocalizations.of(context)!
35+
.shoppingListContainsEntries(shoppinglist.items.length))
36+
],
37+
),
38+
));
39+
}
40+
1741
@override
1842
Widget build(BuildContext context) {
1943
return Scaffold(
@@ -66,20 +90,9 @@ class HouseholdSettingsShoppinglistPage extends StatelessWidget {
6690
state.shoppingLists.elementAt(i).name,
6791
),
6892
isDismissable: i != 0,
69-
confirmDismiss: (direction) async {
70-
return (await askForConfirmation(
71-
context: context,
72-
title: Text(
73-
AppLocalizations.of(context)!.shoppingListDelete,
74-
),
75-
content: Text(
76-
AppLocalizations.of(context)!
77-
.shoppingListDeleteConfirmation(
78-
state.shoppingLists.elementAt(i).name,
79-
),
80-
),
81-
));
82-
},
93+
confirmDismiss: (direction) async =>
94+
await confirmDeleteShoppingList(
95+
context, state.shoppingLists.elementAt(i)),
8396
onDismissed: (direction) {
8497
BlocProvider.of<HouseholdUpdateCubit>(context)
8598
.deleteShoppingList(
@@ -201,17 +214,8 @@ class HouseholdSettingsShoppinglistPage extends StatelessWidget {
201214
}
202215
break;
203216
case _ShoppinglistAction.delete:
204-
if (await askForConfirmation(
205-
context: context,
206-
title: Text(
207-
AppLocalizations.of(context)!.shoppingListDelete,
208-
),
209-
content: Text(
210-
AppLocalizations.of(context)!.shoppingListDeleteConfirmation(
211-
shoppingLists.elementAt(shoppingListIndex).name,
212-
),
213-
),
214-
)) {
217+
if (await confirmDeleteShoppingList(
218+
context, shoppingLists.elementAt(shoppingListIndex))) {
215219
BlocProvider.of<HouseholdUpdateCubit>(context).deleteShoppingList(
216220
shoppingLists.elementAt(shoppingListIndex),
217221
);

0 commit comments

Comments
 (0)