From 56e382127a0600dfc46cb38d08cb91ed8ca2a3d0 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 27 Apr 2022 00:42:00 +0530 Subject: [PATCH 1/2] feat: Remove individual product from the scan carousel --- .../data_models/continuous_scan_model.dart | 9 ++++ .../lib/database/dao_product_list.dart | 8 ++++ .../lib/pages/product/summary_card.dart | 43 ++++++++++++++++--- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/packages/smooth_app/lib/data_models/continuous_scan_model.dart b/packages/smooth_app/lib/data_models/continuous_scan_model.dart index ef9c68a62b3..37651c156aa 100644 --- a/packages/smooth_app/lib/data_models/continuous_scan_model.dart +++ b/packages/smooth_app/lib/data_models/continuous_scan_model.dart @@ -237,6 +237,15 @@ class ContinuousScanModel with ChangeNotifier { await refresh(); } + Future removeBarcode( + final String barcode, + ) async { + await _daoProductList.pop(productList, barcode); + await _daoProductList.pop(_history, barcode); + await refresh(); + notifyListeners(); + } + Future refresh() async { await _refresh(); notifyListeners(); diff --git a/packages/smooth_app/lib/database/dao_product_list.dart b/packages/smooth_app/lib/database/dao_product_list.dart index 682f1875a50..e22470d2bfc 100644 --- a/packages/smooth_app/lib/database/dao_product_list.dart +++ b/packages/smooth_app/lib/database/dao_product_list.dart @@ -161,6 +161,14 @@ class DaoProductList extends AbstractDao { await _put(_getKey(productList), newList); } + Future pop(final ProductList productList, final String barcode) async { + final _BarcodeList? list = await _get(productList); + final List barcodes = list!.barcodes; + barcodes.remove(barcode); + final _BarcodeList newList = _BarcodeList.now(barcodes); + await _put(_getKey(productList), newList); + } + Future clear(final ProductList productList) async => _getBox().delete(_getKey(productList)); diff --git a/packages/smooth_app/lib/pages/product/summary_card.dart b/packages/smooth_app/lib/pages/product/summary_card.dart index 3b082be69b6..69718c76478 100644 --- a/packages/smooth_app/lib/pages/product/summary_card.dart +++ b/packages/smooth_app/lib/pages/product/summary_card.dart @@ -7,6 +7,8 @@ import 'package:openfoodfacts/personalized_search/preference_importance.dart'; import 'package:provider/provider.dart'; import 'package:smooth_app/cards/data_cards/score_card.dart'; import 'package:smooth_app/cards/product_cards/product_title_card.dart'; +import 'package:smooth_app/data_models/continuous_scan_model.dart'; + import 'package:smooth_app/data_models/product_preferences.dart'; import 'package:smooth_app/data_models/user_preferences.dart'; import 'package:smooth_app/database/category_product_query.dart'; @@ -326,13 +328,7 @@ class _SummaryCardState extends State { ), alignment: Alignment.topLeft, padding: const EdgeInsets.symmetric(vertical: SMALL_SPACE), - child: Center( - child: Text( - helper.getHeaderText(AppLocalizations.of(context)!), - style: - Theme.of(context).textTheme.subtitle1!.apply(color: Colors.white), - ), - ), + child: _getHeader(helper), ); } @@ -355,6 +351,39 @@ class _SummaryCardState extends State { ); } + Widget _getHeader(ProductCompatibilityHelper helper) { + if (widget.isFullVersion) { + return Center( + child: Text( + helper.getHeaderText(AppLocalizations.of(context)!), + style: + Theme.of(context).textTheme.subtitle1!.apply(color: Colors.white), + ), + ); + } + final ContinuousScanModel model = context.watch(); + return Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Center( + child: Text( + helper.getHeaderText(AppLocalizations.of(context)!), + style: Theme.of(context) + .textTheme + .subtitle1! + .apply(color: Colors.white), + ), + ), + InkWell( + onTap: () { + model.removeBarcode(widget._product.barcode!); + }, + child: const Icon(Icons.clear_rounded), + ), + ], + ); + } + List _buildAttributeChips(final List attributes) { final List result = []; for (final Attribute attribute in attributes) { From 4770577d4715280d0845ff13a13e08c1cb77f798 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Wed, 27 Apr 2022 21:49:38 +0530 Subject: [PATCH 2/2] updated UI as per mocks --- .../product_cards/product_title_card.dart | 38 ++++++++++++++++--- .../lib/pages/product/summary_card.dart | 37 ++++-------------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/packages/smooth_app/lib/cards/product_cards/product_title_card.dart b/packages/smooth_app/lib/cards/product_cards/product_title_card.dart index 6dd867b1bdf..36c70f40d04 100644 --- a/packages/smooth_app/lib/cards/product_cards/product_title_card.dart +++ b/packages/smooth_app/lib/cards/product_cards/product_title_card.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:openfoodfacts/model/Product.dart'; +import 'package:provider/provider.dart'; +import 'package:smooth_app/data_models/continuous_scan_model.dart'; import 'package:smooth_app/helpers/extension_on_text_helper.dart'; import 'package:smooth_app/helpers/product_cards_helper.dart'; @@ -15,6 +17,35 @@ class ProductTitleCard extends StatelessWidget { Widget build(BuildContext context) { final AppLocalizations appLocalizations = AppLocalizations.of(context)!; final ThemeData themeData = Theme.of(context); + Widget subtitle; + Widget trailingWidget; + if (!isSelectable) { + final ContinuousScanModel model = context.watch(); + subtitle = RichText( + text: TextSpan(children: [ + TextSpan( + text: product.brands ?? appLocalizations.unknownBrand, + ), + const TextSpan(text: ' , '), + TextSpan( + text: product.quantity ?? '', + style: themeData.textTheme.headline3, + ), + ]), + ); + trailingWidget = InkWell( + onTap: () { + model.removeBarcode(product.barcode!); + }, + child: const Icon(Icons.clear_rounded), + ); + } else { + subtitle = Text(product.brands ?? appLocalizations.unknownBrand); + trailingWidget = Text( + product.quantity ?? '', + style: themeData.textTheme.headline3, + ).selectable(isSelectable: isSelectable); + } return Align( alignment: Alignment.topLeft, child: ListTile( @@ -24,11 +55,8 @@ class ProductTitleCard extends StatelessWidget { getProductName(product, appLocalizations), style: themeData.textTheme.headline4, ).selectable(isSelectable: isSelectable), - subtitle: Text(product.brands ?? appLocalizations.unknownBrand), - trailing: Text( - product.quantity ?? '', - style: themeData.textTheme.headline3, - ).selectable(isSelectable: isSelectable), + subtitle: subtitle, + trailing: trailingWidget, ), ); } diff --git a/packages/smooth_app/lib/pages/product/summary_card.dart b/packages/smooth_app/lib/pages/product/summary_card.dart index 775f318b7e9..3b082be69b6 100644 --- a/packages/smooth_app/lib/pages/product/summary_card.dart +++ b/packages/smooth_app/lib/pages/product/summary_card.dart @@ -7,8 +7,6 @@ import 'package:openfoodfacts/personalized_search/preference_importance.dart'; import 'package:provider/provider.dart'; import 'package:smooth_app/cards/data_cards/score_card.dart'; import 'package:smooth_app/cards/product_cards/product_title_card.dart'; -import 'package:smooth_app/data_models/continuous_scan_model.dart'; - import 'package:smooth_app/data_models/product_preferences.dart'; import 'package:smooth_app/data_models/user_preferences.dart'; import 'package:smooth_app/database/category_product_query.dart'; @@ -328,7 +326,13 @@ class _SummaryCardState extends State { ), alignment: Alignment.topLeft, padding: const EdgeInsets.symmetric(vertical: SMALL_SPACE), - child: _getHeader(helper), + child: Center( + child: Text( + helper.getHeaderText(AppLocalizations.of(context)!), + style: + Theme.of(context).textTheme.subtitle1!.apply(color: Colors.white), + ), + ), ); } @@ -351,33 +355,6 @@ class _SummaryCardState extends State { ); } - Widget _getHeader(ProductCompatibilityHelper helper) { - final Widget text = Text( - helper.getHeaderText(AppLocalizations.of(context)!), - style: Theme.of(context).textTheme.subtitle1!.apply(color: Colors.white), - ); - if (widget.isFullVersion) { - return Center( - child: text, - ); - } - final ContinuousScanModel model = context.watch(); - return Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Center( - child: text, - ), - InkWell( - onTap: () { - model.removeBarcode(widget._product.barcode!); - }, - child: const Icon(Icons.clear_rounded), - ), - ], - ); - } - List _buildAttributeChips(final List attributes) { final List result = []; for (final Attribute attribute in attributes) {