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: 5335 - owner field icon/info for "categories" #5845

Merged
merged 1 commit into from
Nov 14, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,7 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
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() {
Expand Down
10 changes: 2 additions & 8 deletions packages/smooth_app/lib/pages/product/nutrition_page_loaded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,7 @@ class _NutritionPageLoadedState extends State<NutritionPageLoaded>
) ==
null
? null
: Semantics(
label: appLocalizations.owner_field_info_title,
child: const Icon(OwnerFieldInfo.ownerFieldIconData),
),
: const OwnerFieldIcon(),
),
textInputAction: TextInputAction.next,
onFieldSubmitted: (_) {
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 15 additions & 4 deletions packages/smooth_app/lib/pages/product/owner_field_info.dart
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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),
);
}
12 changes: 12 additions & 0 deletions packages/smooth_app/lib/pages/product/simple_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -56,6 +57,17 @@ class _SimpleInputPageState extends State<SimpleInputPage> {
final List<Widget> simpleInputs = <Widget>[];
final List<String> titles = <String>[];

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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<String> initTerms(final Product product) =>
product.categoriesTagsInLanguages?[getLanguage()] ?? <String>[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SimpleInputTextField extends StatefulWidget {
this.shapeProvider,
this.padding,
required this.productType,
this.suffixIcon,
});

final FocusNode focusNode;
Expand All @@ -33,6 +34,7 @@ class SimpleInputTextField extends StatefulWidget {
final String? Function()? shapeProvider;
final EdgeInsetsGeometry? padding;
final ProductType? productType;
final Widget? suffixIcon;

@override
State<SimpleInputTextField> createState() => _SimpleInputTextFieldState();
Expand Down Expand Up @@ -81,6 +83,7 @@ class _SimpleInputTextFieldState extends State<SimpleInputTextField> {
hintText: widget.hintText,
constraints: widget.constraints,
manager: _manager,
suffixIcon: widget.suffixIcon,
),
),
if (widget.withClearButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -61,6 +62,7 @@ class _SimpleInputWidgetState extends State<SimpleInputWidget> {
context,
widget.product,
);
final bool isOwnerField = widget.helper.isOwnerField(widget.product);

return Column(
mainAxisAlignment: MainAxisAlignment.start,
Expand Down Expand Up @@ -96,6 +98,7 @@ class _SimpleInputWidgetState extends State<SimpleInputWidget> {
start: 9.0,
),
productType: widget.product.productType,
suffixIcon: !isOwnerField ? null : const OwnerFieldIcon(),
),
),
Tooltip(
Expand Down