diff --git a/packages/smooth_app/lib/pages/product/add_basic_details_page.dart b/packages/smooth_app/lib/pages/product/add_basic_details_page.dart index 88c91695cfd..372a0ab101b 100644 --- a/packages/smooth_app/lib/pages/product/add_basic_details_page.dart +++ b/packages/smooth_app/lib/pages/product/add_basic_details_page.dart @@ -358,10 +358,7 @@ class _AddBasicDetailsPageState extends State { final OpenFoodFactsLanguage? language, }) => _isOwnerField(productField, language: language) - ? Semantics( - label: AppLocalizations.of(context).owner_field_info_title, - child: const Icon(OwnerFieldInfo.ownerFieldIconData), - ) + ? const OwnerFieldIcon() : null; bool _hasOwnerField() { diff --git a/packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart b/packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart index eb9a959c57a..2130c21b8e5 100644 --- a/packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart +++ b/packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart @@ -284,10 +284,7 @@ class _NutritionPageLoadedState extends State ) == null ? null - : Semantics( - label: appLocalizations.owner_field_info_title, - child: const Icon(OwnerFieldInfo.ownerFieldIconData), - ), + : const OwnerFieldIcon(), ), textInputAction: TextInputAction.next, onFieldSubmitted: (_) { @@ -569,10 +566,7 @@ class _NutrientValueCell extends StatelessWidget { product.getOwnerFieldTimestamp(OwnerField.nutrient(nutrient)) == null ? null - : Semantics( - label: appLocalizations.owner_field_info_title, - child: const Icon(OwnerFieldInfo.ownerFieldIconData), - ), + : const OwnerFieldIcon(), ), keyboardType: const TextInputType.numberWithOptions( signed: false, diff --git a/packages/smooth_app/lib/pages/product/owner_field_info.dart b/packages/smooth_app/lib/pages/product/owner_field_info.dart index 189efd9521e..66329284b0c 100644 --- a/packages/smooth_app/lib/pages/product/owner_field_info.dart +++ b/packages/smooth_app/lib/pages/product/owner_field_info.dart @@ -1,13 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +/// Icon to display when the product field value is "producer provided". +const IconData _ownerFieldIconData = Icons.factory; + /// Standard info tile about "owner fields". class OwnerFieldInfo extends StatelessWidget { const OwnerFieldInfo({super.key}); - /// Icon to display when the product field value is "producer provided". - static const IconData ownerFieldIconData = Icons.factory; - @override Widget build(BuildContext context) { final AppLocalizations appLocalizations = AppLocalizations.of(context); @@ -16,9 +16,20 @@ class OwnerFieldInfo extends StatelessWidget { final Color? lightGrey = Colors.grey[300]; return ListTile( tileColor: dark ? darkGrey : lightGrey, - leading: const Icon(ownerFieldIconData), + leading: const Icon(_ownerFieldIconData), title: Text(appLocalizations.owner_field_info_title), subtitle: Text(appLocalizations.owner_field_info_message), ); } } + +/// Standard icon about "owner fields". +class OwnerFieldIcon extends StatelessWidget { + const OwnerFieldIcon(); + + @override + Widget build(BuildContext context) => Semantics( + label: AppLocalizations.of(context).owner_field_info_title, + child: const Icon(_ownerFieldIconData), + ); +} diff --git a/packages/smooth_app/lib/pages/product/simple_input_page.dart b/packages/smooth_app/lib/pages/product/simple_input_page.dart index cb8a55a3db7..22f05b03e81 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_page.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_page.dart @@ -11,6 +11,7 @@ import 'package:smooth_app/helpers/product_cards_helper.dart'; import 'package:smooth_app/pages/input/unfocus_field_when_tap_outside.dart'; import 'package:smooth_app/pages/product/common/product_buttons.dart'; import 'package:smooth_app/pages/product/may_exit_page_helper.dart'; +import 'package:smooth_app/pages/product/owner_field_info.dart'; import 'package:smooth_app/pages/product/simple_input_page_helpers.dart'; import 'package:smooth_app/pages/product/simple_input_widget.dart'; import 'package:smooth_app/widgets/smooth_scaffold.dart'; @@ -56,6 +57,17 @@ class _SimpleInputPageState extends State { final List simpleInputs = []; final List titles = []; + bool hasOwnerField = false; + for (final AbstractSimpleInputPageHelper helper in widget.helpers) { + if (helper.isOwnerField(widget.product)) { + hasOwnerField = true; + break; + } + } + + if (hasOwnerField) { + simpleInputs.add(const OwnerFieldInfo()); + } for (int i = 0; i < widget.helpers.length; i++) { titles.add(widget.helpers[i].getTitle(appLocalizations)); simpleInputs.add( diff --git a/packages/smooth_app/lib/pages/product/simple_input_page_helpers.dart b/packages/smooth_app/lib/pages/product/simple_input_page_helpers.dart index ba8e1c09d86..141ab0cc3eb 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_page_helpers.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_page_helpers.dart @@ -184,6 +184,9 @@ abstract class AbstractSimpleInputPageHelper extends ChangeNotifier { /// Returns the enum to be used for matomo analytics. AnalyticsEditEvents getAnalyticsEditEvent(); + + /// Returns true if the field is an owner field. + bool isOwnerField(final Product product) => false; } /// Implementation for "Stores" of an [AbstractSimpleInputPageHelper]. @@ -396,6 +399,16 @@ class SimpleInputPageLabelHelper extends AbstractSimpleInputPageHelper { /// Implementation for "Categories" of an [AbstractSimpleInputPageHelper]. class SimpleInputPageCategoryHelper extends AbstractSimpleInputPageHelper { + @override + bool isOwnerField(final Product product) => + product.getOwnerFieldTimestamp( + OwnerField.productField( + ProductField.CATEGORIES, + ProductQuery.getLanguage(), + ), + ) != + null; + @override List initTerms(final Product product) => product.categoriesTagsInLanguages?[getLanguage()] ?? []; diff --git a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart index 8854c0b37ab..e2562b1bbdf 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_text_field.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_text_field.dart @@ -19,6 +19,7 @@ class SimpleInputTextField extends StatefulWidget { this.shapeProvider, this.padding, required this.productType, + this.suffixIcon, }); final FocusNode focusNode; @@ -33,6 +34,7 @@ class SimpleInputTextField extends StatefulWidget { final String? Function()? shapeProvider; final EdgeInsetsGeometry? padding; final ProductType? productType; + final Widget? suffixIcon; @override State createState() => _SimpleInputTextFieldState(); @@ -81,6 +83,7 @@ class _SimpleInputTextFieldState extends State { hintText: widget.hintText, constraints: widget.constraints, manager: _manager, + suffixIcon: widget.suffixIcon, ), ), if (widget.withClearButton) diff --git a/packages/smooth_app/lib/pages/product/simple_input_widget.dart b/packages/smooth_app/lib/pages/product/simple_input_widget.dart index f735779af0a..1581e9ff237 100644 --- a/packages/smooth_app/lib/pages/product/simple_input_widget.dart +++ b/packages/smooth_app/lib/pages/product/simple_input_widget.dart @@ -5,6 +5,7 @@ import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/helpers/collections_helper.dart'; import 'package:smooth_app/helpers/haptic_feedback_helper.dart'; import 'package:smooth_app/pages/product/explanation_widget.dart'; +import 'package:smooth_app/pages/product/owner_field_info.dart'; import 'package:smooth_app/pages/product/simple_input_page_helpers.dart'; import 'package:smooth_app/pages/product/simple_input_text_field.dart'; @@ -61,6 +62,7 @@ class _SimpleInputWidgetState extends State { context, widget.product, ); + final bool isOwnerField = widget.helper.isOwnerField(widget.product); return Column( mainAxisAlignment: MainAxisAlignment.start, @@ -96,6 +98,7 @@ class _SimpleInputWidgetState extends State { start: 9.0, ), productType: widget.product.productType, + suffixIcon: !isOwnerField ? null : const OwnerFieldIcon(), ), ), Tooltip(