Skip to content

Commit

Permalink
fix: Text on the scancard should not be selectable (#1434)
Browse files Browse the repository at this point in the history
* fix: Text on the scanner should not be selectable

* converted to if statement

* changed selectable extension

* added style
  • Loading branch information
bhattabhi013 authored Apr 1, 2022
1 parent cb894fa commit fcea379
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import 'package:openfoodfacts/model/Product.dart';
import 'package:smooth_app/helpers/extension_on_text_helper.dart';

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

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

@override
Widget build(BuildContext context) {
Expand All @@ -21,12 +22,12 @@ class ProductTitleCard extends StatelessWidget {
title: Text(
_getProductName(appLocalizations),
style: themeData.textTheme.headline4,
).selectable(),
).selectable(isSelectable: isSelectable),
subtitle: Text(product.brands ?? appLocalizations.unknownBrand),
trailing: Text(
product.quantity ?? '',
style: themeData.textTheme.headline3,
).selectable(),
).selectable(isSelectable: isSelectable),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ class _QuestionCardState extends State<QuestionCard>
padding: const EdgeInsets.symmetric(horizontal: SMALL_SPACE),
child: Column(
children: <Widget>[
ProductTitleCard(widget.product, dense: true),
ProductTitleCard(
widget.product,
true,
dense: true,
),
],
),
),
Expand Down
23 changes: 14 additions & 9 deletions packages/smooth_app/lib/helpers/extension_on_text_helper.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import 'package:flutter/material.dart';

extension Selectable on Text {
Widget selectable() {
return SelectableText(
data!,
style: style,
toolbarOptions: const ToolbarOptions(
copy: true,
selectAll: true,
),
);
Widget selectable({bool isSelectable = true}) {
return isSelectable
? SelectableText(
data!,
style: style,
toolbarOptions: const ToolbarOptions(
copy: true,
selectAll: true,
),
)
: Text(
data!,
style: style,
);
}
}
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/pages/product/summary_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class _SummaryCardState extends State<SummaryCard> {
}
return Column(
children: <Widget>[
ProductTitleCard(widget._product),
ProductTitleCard(widget._product, widget.isFullVersion),
for (final Attribute attribute in scoreAttributes)
ScoreCard(
iconUrl: attribute.iconUrl,
Expand Down

0 comments on commit fcea379

Please sign in to comment.