From 21f816c132c9ae445144db183a615e29016a6f08 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Tue, 8 Oct 2024 16:52:07 +0200 Subject: [PATCH] fix: 5665 - display "add nutrition facts" button only for relevant types Impacted files: * `add_nutrition_button.dart`: new method to check if nutrition facts are relevant for this product type * `knowledge_panel_action_card.dart`: checks if the product type matches before displaying the nutrition facts button * `knowledge_panels_builder.dart`: checks if the product type matches before displaying the nutrition facts button * `pubspec.lock`: upgrade to flutter `3.24` --- .../knowledge_panels/knowledge_panel_action_card.dart | 4 +++- .../lib/knowledge_panel/knowledge_panels_builder.dart | 4 +++- .../smooth_app/lib/pages/product/add_nutrition_button.dart | 4 ++++ packages/smooth_app/pubspec.lock | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/smooth_app/lib/knowledge_panel/knowledge_panels/knowledge_panel_action_card.dart b/packages/smooth_app/lib/knowledge_panel/knowledge_panels/knowledge_panel_action_card.dart index 61c09bbaaad..c212a2d48bf 100644 --- a/packages/smooth_app/lib/knowledge_panel/knowledge_panels/knowledge_panel_action_card.dart +++ b/packages/smooth_app/lib/knowledge_panel/knowledge_panels/knowledge_panel_action_card.dart @@ -65,7 +65,9 @@ class KnowledgePanelActionCard extends StatelessWidget { ); } if (kpAction == KnowledgePanelAction.addNutritionFacts) { - return AddNutritionButton(product); + if (AddNutritionButton.acceptsNutritionFacts(product)) { + return AddNutritionButton(product); + } } Logs.e('unhandled knowledge panel action: $action'); return null; diff --git a/packages/smooth_app/lib/knowledge_panel/knowledge_panels_builder.dart b/packages/smooth_app/lib/knowledge_panel/knowledge_panels_builder.dart index feaff5bacb7..996aff5e5b7 100644 --- a/packages/smooth_app/lib/knowledge_panel/knowledge_panels_builder.dart +++ b/packages/smooth_app/lib/knowledge_panel/knowledge_panels_builder.dart @@ -65,7 +65,9 @@ class KnowledgePanelsBuilder { ProductState.NUTRITION_FACTS_COMPLETED.toBeCompletedTag) ?? false; if (nutritionAddOrUpdate) { - children.add(AddNutritionButton(product)); + if (AddNutritionButton.acceptsNutritionFacts(product)) { + children.add(AddNutritionButton(product)); + } } final bool needEditIngredients = context diff --git a/packages/smooth_app/lib/pages/product/add_nutrition_button.dart b/packages/smooth_app/lib/pages/product/add_nutrition_button.dart index 445fa12d418..27e7b002405 100644 --- a/packages/smooth_app/lib/pages/product/add_nutrition_button.dart +++ b/packages/smooth_app/lib/pages/product/add_nutrition_button.dart @@ -10,6 +10,10 @@ class AddNutritionButton extends StatelessWidget { final Product product; + static bool acceptsNutritionFacts(final Product product) => + product.productType != ProductType.product && + product.productType != ProductType.beauty; + @override Widget build(BuildContext context) => addPanelButton( AppLocalizations.of(context).score_add_missing_nutrition_facts, diff --git a/packages/smooth_app/pubspec.lock b/packages/smooth_app/pubspec.lock index 7218afe031f..fcc8b37871e 100644 --- a/packages/smooth_app/pubspec.lock +++ b/packages/smooth_app/pubspec.lock @@ -1829,4 +1829,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.5.3 <4.0.0" - flutter: ">=3.22.0" + flutter: ">=3.24.0"