Skip to content

Commit

Permalink
feat: Remove individual product from the scan carousel (#1662)
Browse files Browse the repository at this point in the history
* feat: Remove individual product from the scan carousel

* updated UI as per mocks
  • Loading branch information
bhattabhi013 committed Apr 28, 2022
1 parent b87bfbc commit ddc1bac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<ContinuousScanModel>();
subtitle = RichText(
text: TextSpan(children: <InlineSpan>[
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(
Expand All @@ -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,
),
);
}
Expand Down
12 changes: 12 additions & 0 deletions packages/smooth_app/lib/data_models/continuous_scan_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ class ContinuousScanModel with ChangeNotifier {
await refresh();
}

Future<void> removeBarcode(
final String barcode,
) async {
await _daoProductList.set(
productList,
barcode,
false,
);
await refresh();
notifyListeners();
}

Future<void> refresh() async {
await _refresh();
notifyListeners();
Expand Down

0 comments on commit ddc1bac

Please sign in to comment.