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: 3526 - added "add extra photo" button for both edit packaging pages #3560

Merged
merged 2 commits into from
Jan 14, 2023
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
4 changes: 4 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,10 @@
"@add_photo_button_label": {
"description": "Label for the add photo button"
},
"add_packaging_photo_button_label": "Take photos of any packaging/recycling information",
"@add_packaging_photo_button_label": {
"description": "Label for the add PACKAGING photo button"
},
"choose_image_source_title": "Choose image source",
"@choose_image_source_title": {
"description": "Title for the image source chooser"
Expand Down
32 changes: 28 additions & 4 deletions packages/smooth_app/lib/pages/product/edit_new_packagings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/image_crop_page.dart';
import 'package:smooth_app/pages/product/explanation_widget.dart';
import 'package:smooth_app/pages/product/may_exit_page_helper.dart';
import 'package:smooth_app/pages/product/simple_input_widget.dart';
Expand Down Expand Up @@ -169,15 +171,37 @@ class _EditNewPackagingsState extends State<EditNewPackagings> {
);
children.add(
Padding(
padding: const EdgeInsets.all(VERY_LARGE_SPACE),
child: ElevatedButton.icon(
label: Text(appLocalizations.edit_packagings_element_add),
icon: const Icon(Icons.add),
padding: const EdgeInsets.only(
top: VERY_LARGE_SPACE,
left: SMALL_SPACE,
right: SMALL_SPACE,
),
child: addPanelButton(
appLocalizations.edit_packagings_element_add.toUpperCase(),
iconData: Icons.add,
onPressed: () =>
setState(() => _addPackagingToControllers(ProductPackaging())),
),
),
);
children.add(
Padding(
padding: const EdgeInsets.only(
bottom: VERY_LARGE_SPACE,
left: SMALL_SPACE,
right: SMALL_SPACE,
),
child: addPanelButton(
appLocalizations.add_packaging_photo_button_label.toUpperCase(),
onPressed: () async => confirmAndUploadNewPicture(
this,
imageField: ImageField.OTHER,
barcode: widget.product.barcode!,
),
iconData: Icons.add_a_photo,
),
),
);
children.add(
Padding(
padding: const EdgeInsets.symmetric(horizontal: SMALL_SPACE),
Expand Down
3 changes: 3 additions & 0 deletions packages/smooth_app/lib/pages/product/ocr_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ abstract class OcrHelper {
/// Stamp to identify similar updates on the same product.
BackgroundTaskDetailsStamp getStamp();

/// Returns true if we need to put an "add extra photos" button.
bool hasAddExtraPhotoButton();

@protected
OpenFoodFactsLanguage getLanguage() => ProductQuery.getLanguage()!;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ class OcrIngredientsHelper extends OcrHelper {
@override
BackgroundTaskDetailsStamp getStamp() =>
BackgroundTaskDetailsStamp.ocrIngredients;

@override
bool hasAddExtraPhotoButton() => false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ class OcrPackagingHelper extends OcrHelper {
@override
BackgroundTaskDetailsStamp getStamp() =>
BackgroundTaskDetailsStamp.ocrPackaging;

@override
bool hasAddExtraPhotoButton() => true;
}
59 changes: 43 additions & 16 deletions packages/smooth_app/lib/pages/product/ocr_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import 'package:smooth_app/data_models/product_image_data.dart';
import 'package:smooth_app/database/transient_file.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/image_crop_page.dart';
import 'package:smooth_app/pages/product/explanation_widget.dart';
import 'package:smooth_app/pages/product/ocr_helper.dart';

/// Widget dedicated to OCR, with 3 actions: upload image, extract data, save.
class OcrWidget extends StatelessWidget {
///
/// Potential extra action: add extra photos.
class OcrWidget extends StatefulWidget {
const OcrWidget({
required this.controller,
required this.onSubmitField,
Expand All @@ -28,6 +32,11 @@ class OcrWidget extends StatelessWidget {
final Product product;
final OcrHelper helper;

@override
State<OcrWidget> createState() => _OcrWidgetState();
}

class _OcrWidgetState extends State<OcrWidget> {
@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
Expand All @@ -49,12 +58,12 @@ class OcrWidget extends StatelessWidget {
child: SmoothActionButtonsBar(
positiveAction: SmoothActionButton(
text: (TransientFile.isImageAvailable(
productImageData,
product.barcode!,
widget.productImageData,
widget.product.barcode!,
))
? helper.getActionRefreshPhoto(appLocalizations)
? widget.helper.getActionRefreshPhoto(appLocalizations)
: appLocalizations.upload_image,
onPressed: () async => onTapNewImage(),
onPressed: () async => widget.onTapNewImage(),
),
),
),
Expand All @@ -75,24 +84,25 @@ class OcrWidget extends StatelessWidget {
child: Column(
children: <Widget>[
if (TransientFile.isServerImage(
productImageData,
product.barcode!,
widget.productImageData,
widget.product.barcode!,
))
SmoothActionButtonsBar.single(
action: SmoothActionButton(
text: helper.getActionExtractText(appLocalizations),
onPressed: () async => onTapExtractData(),
text: widget.helper
.getActionExtractText(appLocalizations),
onPressed: () async => widget.onTapExtractData(),
),
)
else if (TransientFile.isImageAvailable(
productImageData,
product.barcode!,
widget.productImageData,
widget.product.barcode!,
))
// TODO(monsieurtanuki): what if slow upload? text instead?
const CircularProgressIndicator.adaptive(),
const SizedBox(height: MEDIUM_SPACE),
TextField(
controller: controller,
controller: widget.controller,
decoration: InputDecoration(
fillColor: Colors.white.withOpacity(0.2),
filled: true,
Expand All @@ -103,12 +113,26 @@ class OcrWidget extends StatelessWidget {
maxLines: null,
textInputAction: TextInputAction.done,
onSubmitted: (_) =>
onSubmitField(helper.getImageField()),
widget.onSubmitField(widget.helper.getImageField()),
),
const SizedBox(height: SMALL_SPACE),
ExplanationWidget(
helper.getInstructions(appLocalizations),
widget.helper.getInstructions(appLocalizations),
),
if (widget.helper.hasAddExtraPhotoButton())
Padding(
padding: const EdgeInsets.only(top: SMALL_SPACE),
child: addPanelButton(
appLocalizations.add_packaging_photo_button_label
.toUpperCase(),
onPressed: () async => confirmAndUploadNewPicture(
this,
imageField: ImageField.OTHER,
barcode: widget.product.barcode!,
),
iconData: Icons.add_a_photo,
),
),
const SizedBox(height: MEDIUM_SPACE),
SmoothActionButtonsBar(
axis: Axis.horizontal,
Expand All @@ -119,8 +143,11 @@ class OcrWidget extends StatelessWidget {
positiveAction: SmoothActionButton(
text: appLocalizations.save,
onPressed: () async {
await onSubmitField(helper.getImageField());
////ignore: use_build_context_synchronously
await widget
.onSubmitField(widget.helper.getImageField());
if (!mounted) {
return;
}
Navigator.pop(context);
},
),
Expand Down