Skip to content

Commit

Permalink
feature: Ask before deleting shopping lists with entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Guilherme Bufolo authored and TomBursch committed Dec 13, 2024
1 parent b89e0f3 commit aa73c15
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 @@ -294,6 +294,13 @@
"@setupTitle": {},
"@share": {},
"@shoppingList": {},
"@shoppingListContainsEntries": {
"placeholders": {
"entriesCount": {
"type": "num"
}
}
},
"@shoppingListDelete": {},
"@shoppingListDeleteConfirmation": {
"placeholders": {
Expand Down Expand Up @@ -578,6 +585,7 @@
"setupTitle": "Hey there! Ready to shop?",
"share": "Share",
"shoppingList": "Shopping list",
"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.}}",
"shoppingListDelete": "Delete shopping list",
"shoppingListDeleteConfirmation": "Are you sure you want to delete {shoppingList}?",
"shoppingListEdit": "Edit shopping list",
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 aa73c15

Please sign in to comment.