diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index c0106c39e35..b17b477e5dd 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -999,10 +999,22 @@ "count": {} } }, - "compare_products_mode": "Compare products", + "compare_products_mode": "Compare selected products", "@compare_products_mode": { "description": "Button to switch to 'compare products mode'" }, + "delete_products_mode": "Delete selected products", + "@delete_products_mode": { + "description": "Button to switch to 'delete products'" + }, + "select_all_products_mode": "Select all products", + "@select_all_products_mode": { + "description": "Button to switch to 'select all products'" + }, + "select_none_products_mode": "Select none", + "@select_none_products_mode": { + "description": "Button to switch to 'select no products'" + }, "compare_products_appbar_title": "Compare products", "@compare_products_appbar_title": { "description": "AppBar title when in comparison mode " diff --git a/packages/smooth_app/lib/pages/product/common/product_list_item_popup_items.dart b/packages/smooth_app/lib/pages/product/common/product_list_item_popup_items.dart index ed67bb929bd..80a07134e05 100644 --- a/packages/smooth_app/lib/pages/product/common/product_list_item_popup_items.dart +++ b/packages/smooth_app/lib/pages/product/common/product_list_item_popup_items.dart @@ -37,7 +37,7 @@ abstract class ProductListItemPopupItem { required final ProductList productList, required final LocalDatabase localDatabase, required final BuildContext context, - required final Iterable selectedBarcodes, + required final Set selectedBarcodes, }); /// Returns the popup menu item. @@ -68,7 +68,7 @@ class ProductListItemPopupSideBySide extends ProductListItemPopupItem { required final ProductList productList, required final LocalDatabase localDatabase, required final BuildContext context, - required final Iterable selectedBarcodes, + required final Set selectedBarcodes, }) async { final OrderedNutrientsCache? cache = await OrderedNutrientsCache.getCache(context); @@ -118,7 +118,7 @@ class ProductListItemPopupRank extends ProductListItemPopupItem { required final ProductList productList, required final LocalDatabase localDatabase, required final BuildContext context, - required final Iterable selectedBarcodes, + required final Set selectedBarcodes, }) async { await Navigator.push( context, @@ -137,7 +137,7 @@ class ProductListItemPopupRank extends ProductListItemPopupItem { class ProductListItemPopupDelete extends ProductListItemPopupItem { @override String getTitle(final AppLocalizations appLocalizations) => - 'Delete selected items'; //appLocalizations.action_delete_list; + appLocalizations.delete_products_mode; @override IconData getIconData() => Icons.delete; @@ -150,7 +150,7 @@ class ProductListItemPopupDelete extends ProductListItemPopupItem { required final ProductList productList, required final LocalDatabase localDatabase, required final BuildContext context, - required final Iterable selectedBarcodes, + required final Set selectedBarcodes, }) async { final AppLocalizations appLocalizations = AppLocalizations.of(context); final DaoProductList daoProductList = DaoProductList(localDatabase); @@ -190,3 +190,45 @@ class ProductListItemPopupDelete extends ProductListItemPopupItem { return true; } } + +/// Popup menu item for the product list page: select all items. +class ProductListItemPopupSelectAll extends ProductListItemPopupItem { + @override + String getTitle(final AppLocalizations appLocalizations) => + appLocalizations.select_all_products_mode; + + @override + IconData getIconData() => Icons.check_box; + + @override + Future doSomething({ + required final ProductList productList, + required final LocalDatabase localDatabase, + required final BuildContext context, + required final Set selectedBarcodes, + }) async { + selectedBarcodes.addAll(productList.barcodes); + return true; + } +} + +/// Popup menu item for the product list page: unselect all items. +class ProductListItemPopupUnselectAll extends ProductListItemPopupItem { + @override + String getTitle(final AppLocalizations appLocalizations) => + appLocalizations.select_none_products_mode; + + @override + IconData getIconData() => Icons.clear; + + @override + Future doSomething({ + required final ProductList productList, + required final LocalDatabase localDatabase, + required final BuildContext context, + required final Set selectedBarcodes, + }) async { + selectedBarcodes.clear(); + return true; + } +} diff --git a/packages/smooth_app/lib/pages/product/common/product_list_page.dart b/packages/smooth_app/lib/pages/product/common/product_list_page.dart index 3f14e0f602b..be438ab8f44 100644 --- a/packages/smooth_app/lib/pages/product/common/product_list_page.dart +++ b/packages/smooth_app/lib/pages/product/common/product_list_page.dart @@ -75,6 +75,10 @@ class _ProductListPageState extends State final ProductListItemPopupItem _rankItems = ProductListItemPopupRank(); final ProductListItemPopupItem _sideBySideItems = ProductListItemPopupSideBySide(); + final ProductListItemPopupItem _selectAllItems = + ProductListItemPopupSelectAll(); + final ProductListItemPopupItem _selectNoneItems = + ProductListItemPopupUnselectAll(); //returns bool to handle WillPopScope Future _handleUserBacktap() async { @@ -216,6 +220,14 @@ class _ProductListPageState extends State appLocalizations, _selectedBarcodes.isNotEmpty, ), + _selectAllItems.getMenuItem( + appLocalizations, + _selectedBarcodes.length < productList.barcodes.length, + ), + _selectNoneItems.getMenuItem( + appLocalizations, + _selectedBarcodes.isNotEmpty, + ), ], ), ],