Skip to content

Commit

Permalink
feat: 3297 - added an "add pics" button to the "edit origins" widget (#…
Browse files Browse the repository at this point in the history
…4863)

* feat: 3297 - added an "add pics" button to the "edit origins" widget

Impacted files:
* `app_en.arb`: added label for "add origin pics"
* `app_fr.arb`: added label for "add origin pics"
* `simple_input_page_helpers.dart`: added an "extra widget" for simple inputs, and implemented it for "origins" with an "add photo" button; minor refactoring on `getIcon`
* `simple_input_widget.dart`: minor refactoring

* feat: 3297 - added extra buttons for emb and labels

Impacted files:
* `app_en.arb`: added labels for "add pics" buttons (emb and labels)
* `app_fr.arb`: added labels for "add pics" buttons (emb and labels)
* `simple_input_page_helpers.dart`: added extra buttons for emb and labels
* `smooth_large_button_with_icon.dart`: minor UI fix
  • Loading branch information
monsieurtanuki authored Nov 30, 2023
1 parent 47439a9 commit 2b8d592
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SmoothLargeButtonWithIcon extends StatelessWidget {
flex: 10,
child: AutoSizeText(
text,
maxLines: 2,
maxLines: 3,
minFontSize: 10,
textAlign: textAlign,
style: style,
Expand Down
12 changes: 12 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,18 @@
"@add_packaging_photo_button_label": {
"description": "Label for the add PACKAGING photo button"
},
"add_origin_photo_button_label": "Take photos of any origin information",
"@add_origin_photo_button_label": {
"description": "Label for the add ORIGIN photo button"
},
"add_emb_photo_button_label": "Take photos of any traceability code information",
"@add_emb_photo_button_label": {
"description": "Label for the add EMB photo button"
},
"add_label_photo_button_label": "Take photos of any labels & certifications information",
"@add_label_photo_button_label": {
"description": "Label for the add LABELS photo button"
},
"choose_image_source_title": "Choose image source",
"@choose_image_source_title": {
"description": "Title for the image source chooser"
Expand Down
12 changes: 12 additions & 0 deletions packages/smooth_app/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,18 @@
"@add_packaging_photo_button_label": {
"description": "Label for the add PACKAGING photo button"
},
"add_origin_photo_button_label": "Prenez des photos de toute information sur les origines",
"@add_origin_photo_button_label": {
"description": "Label for the add ORIGIN photo button"
},
"add_emb_photo_button_label": "Prenez des photos de toute information sur les codes de traçabilité",
"@add_emb_photo_button_label": {
"description": "Label for the add EMB photo button"
},
"add_label_photo_button_label": "Prenez des photos de toute information sur les labels & certifications",
"@add_label_photo_button_label": {
"description": "Label for the add LABELS photo button"
},
"choose_image_source_title": "Choisissez la source de l'image",
"@choose_image_source_title": {
"description": "Title for the image source chooser"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/background/background_task_details.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/image_crop_page.dart';
import 'package:smooth_app/query/product_query.dart';

/// Abstract helper for Simple Input Page.
Expand Down Expand Up @@ -100,7 +103,40 @@ abstract class AbstractSimpleInputPageHelper extends ChangeNotifier {
TagType? getTagType();

/// Returns the icon data for the list tile.
Widget? getIcon() => null;
Widget getIcon();

/// Extra widget to be displayed after the list.
Widget? getExtraWidget(
final BuildContext context,
final Product product,
) =>
null;

/// Typical extra widget for the "add other pics" button.
@protected
Widget getExtraPhotoWidget(
final BuildContext context,
final Product product,
final String title,
) =>
Padding(
padding: const EdgeInsets.symmetric(
vertical: VERY_LARGE_SPACE,
horizontal: SMALL_SPACE,
),
child: addPanelButton(
title.toUpperCase(),
onPressed: () async => confirmAndUploadNewPicture(
context,
imageField: ImageField.OTHER,
barcode: product.barcode!,
language: ProductQuery.getLanguage(),
// we're already logged in if needed
isLoggedInMandatory: false,
),
iconData: Icons.add_a_photo,
),
);

/// Returns true if changes were made.
bool getChangedProduct(final Product product) {
Expand Down Expand Up @@ -177,7 +213,7 @@ class SimpleInputPageStoreHelper extends AbstractSimpleInputPageHelper {
TagType? getTagType() => null;

@override
Widget? getIcon() => const Icon(Icons.shopping_cart);
Widget getIcon() => const Icon(Icons.shopping_cart);

@override
BackgroundTaskDetailsStamp getStamp() => BackgroundTaskDetailsStamp.stores;
Expand Down Expand Up @@ -221,13 +257,24 @@ class SimpleInputPageOriginHelper extends AbstractSimpleInputPageHelper {
TagType? getTagType() => TagType.ORIGINS;

@override
Widget? getIcon() => const Icon(Icons.travel_explore);
Widget getIcon() => const Icon(Icons.travel_explore);

@override
BackgroundTaskDetailsStamp getStamp() => BackgroundTaskDetailsStamp.origins;

@override
AnalyticsEditEvents getAnalyticsEditEvent() => AnalyticsEditEvents.origins;

@override
Widget? getExtraWidget(
final BuildContext context,
final Product product,
) =>
getExtraPhotoWidget(
context,
product,
AppLocalizations.of(context).add_origin_photo_button_label,
);
}

/// Implementation for "Emb Code" of an [AbstractSimpleInputPageHelper].
Expand Down Expand Up @@ -264,14 +311,25 @@ class SimpleInputPageEmbCodeHelper extends AbstractSimpleInputPageHelper {
TagType? getTagType() => TagType.EMB_CODES;

@override
Widget? getIcon() => const Icon(Icons.factory);
Widget getIcon() => const Icon(Icons.factory);

@override
BackgroundTaskDetailsStamp getStamp() => BackgroundTaskDetailsStamp.embCodes;

@override
AnalyticsEditEvents getAnalyticsEditEvent() =>
AnalyticsEditEvents.traceabilityCodes;

@override
Widget? getExtraWidget(
final BuildContext context,
final Product product,
) =>
getExtraPhotoWidget(
context,
product,
AppLocalizations.of(context).add_emb_photo_button_label,
);
}

/// Implementation for "Labels" of an [AbstractSimpleInputPageHelper].
Expand Down Expand Up @@ -313,14 +371,25 @@ class SimpleInputPageLabelHelper extends AbstractSimpleInputPageHelper {
TagType? getTagType() => TagType.LABELS;

@override
Widget? getIcon() => const Icon(Icons.local_offer);
Widget getIcon() => const Icon(Icons.local_offer);

@override
BackgroundTaskDetailsStamp getStamp() => BackgroundTaskDetailsStamp.labels;

@override
AnalyticsEditEvents getAnalyticsEditEvent() =>
AnalyticsEditEvents.labelsAndCertifications;

@override
Widget? getExtraWidget(
final BuildContext context,
final Product product,
) =>
getExtraPhotoWidget(
context,
product,
AppLocalizations.of(context).add_label_photo_button_label,
);
}

/// Implementation for "Categories" of an [AbstractSimpleInputPageHelper].
Expand Down Expand Up @@ -366,7 +435,7 @@ class SimpleInputPageCategoryHelper extends AbstractSimpleInputPageHelper {
TagType? getTagType() => TagType.CATEGORIES;

@override
Widget? getIcon() => const Icon(Icons.restaurant);
Widget getIcon() => const Icon(Icons.restaurant);

@override
BackgroundTaskDetailsStamp getStamp() =>
Expand Down Expand Up @@ -415,7 +484,7 @@ class SimpleInputPageCountryHelper extends AbstractSimpleInputPageHelper {
TagType? getTagType() => TagType.COUNTRIES;

@override
Widget? getIcon() => const Icon(Icons.public);
Widget getIcon() => const Icon(Icons.public);

@override
BackgroundTaskDetailsStamp getStamp() => BackgroundTaskDetailsStamp.countries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class _SimpleInputWidgetState extends State<SimpleInputWidget> {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final String? explanations =
widget.helper.getAddExplanations(appLocalizations);
final Widget? extraWidget = widget.helper.getExtraWidget(
context,
widget.product,
);

return Column(
mainAxisAlignment: MainAxisAlignment.start,
Expand Down Expand Up @@ -142,6 +146,7 @@ class _SimpleInputWidgetState extends State<SimpleInputWidget> {
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
),
if (extraWidget != null) extraWidget,
],
);
}
Expand Down

0 comments on commit 2b8d592

Please sign in to comment.