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

fix: #1720 - now we cannot remove a product from onboarding #1721

Merged
merged 1 commit into from
Apr 30, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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