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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ class ContinuousScanModel with ChangeNotifier {
await refresh();
}

Future<void> removeBarcode(
final String barcode,
) async {
await _daoProductList.pop(productList, barcode);
await _daoProductList.pop(_history, barcode);
bhattabhi013 marked this conversation as resolved.
Show resolved Hide resolved
await refresh();
notifyListeners();
}

Future<void> refresh() async {
await _refresh();
notifyListeners();
Expand Down
8 changes: 8 additions & 0 deletions packages/smooth_app/lib/database/dao_product_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ class DaoProductList extends AbstractDao {
await _put(_getKey(productList), newList);
}

Future<void> pop(final ProductList productList, final String barcode) async {
final _BarcodeList? list = await _get(productList);
final List<String> barcodes = list!.barcodes;
barcodes.remove(barcode);
final _BarcodeList newList = _BarcodeList.now(barcodes);
await _put(_getKey(productList), newList);
}

Future<void> clear(final ProductList productList) async =>
_getBox().delete(_getKey(productList));

Expand Down
43 changes: 36 additions & 7 deletions packages/smooth_app/lib/pages/product/summary_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -326,13 +328,7 @@ class _SummaryCardState extends State<SummaryCard> {
),
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),
);
}

Expand All @@ -355,6 +351,39 @@ class _SummaryCardState extends State<SummaryCard> {
);
}

Widget _getHeader(ProductCompatibilityHelper helper) {
if (widget.isFullVersion) {
return Center(
child: Text(
bhattabhi013 marked this conversation as resolved.
Show resolved Hide resolved
helper.getHeaderText(AppLocalizations.of(context)!),
style:
Theme.of(context).textTheme.subtitle1!.apply(color: Colors.white),
),
);
}
final ContinuousScanModel model = context.watch<ContinuousScanModel>();
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
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<Widget> _buildAttributeChips(final List<Attribute> attributes) {
final List<Widget> result = <Widget>[];
for (final Attribute attribute in attributes) {
Expand Down