Skip to content

Commit

Permalink
feat: openfoodfacts#2705 - barcode copy from product edit page (openf…
Browse files Browse the repository at this point in the history
…oodfacts#2709)

Impacted files:
* `edit_product_page.dart`: added a "Copy" button close to the barcode, and a `Snackbar` after the copy to clipboard
* `app_en.arb`: added 1 snackbar label to acknowlegde the barcode copy
  • Loading branch information
monsieurtanuki authored Aug 1, 2022
1 parent 6be24de commit a713ccd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
10 changes: 10 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,16 @@
"@no_internet_connection": {
"description": "Message when there is no internet connection"
},
"clipboard_barcode_copied": "Barcode {barcode} copied to the clipboard!",
"@clipboard_barcode_copied": {
"description": "Snackbar label after clipboard copy",
"placeholders": {
"barcode": {
"type": "String",
"description": "barcode"
}
}
},
"choose_app_language": "Choose App Language",
"@choose_app_language": {
"description": "Choose Application Language"
Expand Down
57 changes: 38 additions & 19 deletions packages/smooth_app/lib/pages/product/edit_product_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:barcode_widget/barcode_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
Expand Down Expand Up @@ -45,7 +46,6 @@ class _EditProductPageState extends State<EditProductPage> {
@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final Size screenSize = MediaQuery.of(context).size;
return Consumer<UpToDateProductProvider>(
builder: (
final BuildContext context,
Expand All @@ -70,25 +70,44 @@ class _EditProductPageState extends State<EditProductPage> {
child: ListView(
children: <Widget>[
if (_product.barcode != null)
BarcodeWidget(
padding: EdgeInsets.symmetric(
horizontal: screenSize.width / 4,
vertical: SMALL_SPACE,
),
barcode: _product.barcode!.length == 8
? Barcode.ean8()
: Barcode.ean13(),
color: brightness == Brightness.dark
? Colors.white
: Colors.black,
data: _product.barcode!,
errorBuilder: (final BuildContext context, String? _) =>
ListTile(
title: Text(
appLocalizations.edit_product_form_item_barcode,
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const SizedBox(width: MINIMUM_TOUCH_SIZE),
BarcodeWidget(
barcode: _product.barcode!.length == 8
? Barcode.ean8()
: Barcode.ean13(),
data: _product.barcode!,
color: brightness == Brightness.dark
? Colors.white
: Colors.black,
errorBuilder: (final BuildContext context, String? _) =>
Text(
'${appLocalizations.edit_product_form_item_barcode}\n'
'${_product.barcode}',
textAlign: TextAlign.center,
),
),
subtitle: Text(_product.barcode!),
),
IconButton(
icon: const Icon(Icons.copy),
iconSize: MINIMUM_TOUCH_SIZE,
onPressed: () {
Clipboard.setData(
ClipboardData(text: _product.barcode),
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
appLocalizations.clipboard_barcode_copied(
_product.barcode!),
),
),
);
},
)
],
),
_ListTitleItem(
title: appLocalizations.edit_product_form_item_details_title,
Expand Down

0 comments on commit a713ccd

Please sign in to comment.