Skip to content

Commit

Permalink
fix: #1720 - now we cannot remove a product from onboarding
Browse files Browse the repository at this point in the history
There was a Carousel/Provider side-effect.

Impacted files:
* `preferences_page.dart`: used new parameter `isRemovable`
* `product_title_card.dart`: new parameter `isRemovable`
* `summary_card.dart`: new parameter `isRemovable`
  • Loading branch information
monsieurtanuki committed Apr 30, 2022
1 parent bd10bbb commit b8ebc0b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
41 changes: 19 additions & 22 deletions packages/smooth_app/lib/cards/product_cards/product_title_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,37 @@ import 'package:smooth_app/helpers/extension_on_text_helper.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';

class ProductTitleCard extends StatelessWidget {
const ProductTitleCard(this.product, this.isSelectable, {this.dense = false});
const ProductTitleCard(
this.product,
this.isSelectable, {
this.dense = false,
this.isRemovable = true,
});

final Product product;
final bool dense;
final bool isSelectable;
final bool isRemovable;

@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context)!;
final ThemeData themeData = Theme.of(context);
Widget subtitle;
Widget trailingWidget;
if (!isSelectable) {
final String subtitleText;
final Widget trailingWidget;
final String brands = product.brands ?? appLocalizations.unknownBrand;
final String quantity = product.quantity ?? '';
if (isRemovable) {
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,
),
]),
);
subtitleText = '$brands${quantity == '' ? '' : ', $quantity'}';
trailingWidget = InkWell(
onTap: () {
model.removeBarcode(product.barcode!);
},
onTap: () async => model.removeBarcode(product.barcode!),
child: const Icon(Icons.clear_rounded),
);
} else {
subtitle = Text(product.brands ?? appLocalizations.unknownBrand);
subtitleText = brands;
trailingWidget = Text(
product.quantity ?? '',
quantity,
style: themeData.textTheme.headline3,
).selectable(isSelectable: isSelectable);
}
Expand All @@ -55,7 +50,9 @@ class ProductTitleCard extends StatelessWidget {
getProductName(product, appLocalizations),
style: themeData.textTheme.headline4,
).selectable(isSelectable: isSelectable),
subtitle: subtitle,
subtitle: Text(
subtitleText,
).selectable(isSelectable: isSelectable),
trailing: trailingWidget,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class _HelperState extends State<_Helper> {
widget.product,
productPreferences,
isFullVersion: _isProductExpanded,
isRemovable: false,
),
),
),
Expand Down
10 changes: 9 additions & 1 deletion packages/smooth_app/lib/pages/product/summary_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class SummaryCard extends StatefulWidget {
this.isFullVersion = false,
this.showUnansweredQuestions = false,
this.refreshProductCallback,
this.isRemovable = true,
});

final Product _product;
Expand All @@ -62,6 +63,9 @@ class SummaryCard extends StatefulWidget {
/// product and give a prompt to answer those questions.
final bool showUnansweredQuestions;

/// If true, there will be a button to remove the product from the carousel.
final bool isRemovable;

/// Callback to refresh the product when necessary.
final Function(BuildContext)? refreshProductCallback;

Expand Down Expand Up @@ -294,7 +298,11 @@ class _SummaryCardState extends State<SummaryCard> {

return Column(
children: <Widget>[
ProductTitleCard(widget._product, widget.isFullVersion),
ProductTitleCard(
widget._product,
widget.isFullVersion,
isRemovable: widget.isRemovable,
),
for (final Attribute attribute in scoreAttributes)
InkWell(
onTap: () async => openFullKnowledgePanel(
Expand Down

0 comments on commit b8ebc0b

Please sign in to comment.