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 2 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
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
37 changes: 30 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,33 @@ class _SummaryCardState extends State<SummaryCard> {
);
}

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<ContinuousScanModel>();
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Center(
child: text,
),
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