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

feat: Remove individual product from the scan carousel #1662

Merged
merged 3 commits into from
Apr 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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