Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ask before deleting not empty list #575

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading