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/data_models/continuous_scan_model.dart b/packages/smooth_app/lib/data_models/continuous_scan_model.dart index ef9c68a62b3..c8c4cf09660 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,18 @@ class ContinuousScanModel with ChangeNotifier { await refresh(); } + Future removeBarcode( + final String barcode, + ) async { + await _daoProductList.set( + productList, + barcode, + false, + ); + await refresh(); + notifyListeners(); + } + Future refresh() async { await _refresh(); notifyListeners();