Skip to content

Commit

Permalink
feature: Ask before deleteing shopping lists with entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilherme Bufolo authored and RedX2501 committed Dec 13, 2024
1 parent c5d8af6 commit 1330532
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
8 changes: 8 additions & 0 deletions kitchenowl/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@
"shoppingList": {}
}
},
"@shoppingListContainsEntries": {
"placeholders": {
"entriesCount": {
"type": "num"
}
}
},
"@shoppingListEdit": {},
"@shoppingListStyle": {},
"@shoppingLists": {},
Expand Down Expand Up @@ -580,6 +587,7 @@
"shoppingList": "Shopping list",
"shoppingListDelete": "Delete shopping list",
"shoppingListDeleteConfirmation": "Are you sure you want to delete {shoppingList}?",
"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.}}",
"shoppingListEdit": "Edit shopping list",
"shoppingListStyle": "Shopping list style",
"shoppingLists": "Shopping lists",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ enum _ShoppinglistAction {
class HouseholdSettingsShoppinglistPage extends StatelessWidget {
const HouseholdSettingsShoppinglistPage({super.key});

static Future<bool> confirmDeleteShoppingList(
BuildContext context, ShoppingList shoppinglist) async {
return await askForConfirmation(
context: context,
title: Text(
AppLocalizations.of(context)!.shoppingListDelete,
),
content: SingleChildScrollView(
child: ListBody(
children: [
Text(
AppLocalizations.of(context)!.shoppingListDeleteConfirmation(
shoppinglist.name,
),
),
if (shoppinglist.items.length > 0) const SizedBox(height: 20),
if (shoppinglist.items.length > 0)
Text(AppLocalizations.of(context)!
.shoppingListContainsEntries(shoppinglist.items.length))
],
),
));
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -66,20 +90,9 @@ class HouseholdSettingsShoppinglistPage extends StatelessWidget {
state.shoppingLists.elementAt(i).name,
),
isDismissable: i != 0,
confirmDismiss: (direction) async {
return (await askForConfirmation(
context: context,
title: Text(
AppLocalizations.of(context)!.shoppingListDelete,
),
content: Text(
AppLocalizations.of(context)!
.shoppingListDeleteConfirmation(
state.shoppingLists.elementAt(i).name,
),
),
));
},
confirmDismiss: (direction) async =>
await confirmDeleteShoppingList(
context, state.shoppingLists.elementAt(i)),
onDismissed: (direction) {
BlocProvider.of<HouseholdUpdateCubit>(context)
.deleteShoppingList(
Expand Down Expand Up @@ -201,17 +214,8 @@ class HouseholdSettingsShoppinglistPage extends StatelessWidget {
}
break;
case _ShoppinglistAction.delete:
if (await askForConfirmation(
context: context,
title: Text(
AppLocalizations.of(context)!.shoppingListDelete,
),
content: Text(
AppLocalizations.of(context)!.shoppingListDeleteConfirmation(
shoppingLists.elementAt(shoppingListIndex).name,
),
),
)) {
if (await confirmDeleteShoppingList(
context, shoppingLists.elementAt(shoppingListIndex))) {
BlocProvider.of<HouseholdUpdateCubit>(context).deleteShoppingList(
shoppingLists.elementAt(shoppingListIndex),
);
Expand Down

0 comments on commit 1330532

Please sign in to comment.