From af7ce556609dad6c71cde356f58d0680f6c72a16 Mon Sep 17 00:00:00 2001 From: cli1005 <87010739+cli1005@users.noreply.github.com> Date: Fri, 29 Apr 2022 17:36:29 +0200 Subject: [PATCH] fix: #1540 - duplicated panel title (#1665) * fix: #1540 - duplicated panel title * fix: #1540 - refactoring --- .../knowledge_panel_summary_card.dart | 9 -------- .../knowledge_panels_builder.dart | 21 ++++++++++++++++--- .../knowledge_panel_page_template.dart | 1 + 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/smooth_app/lib/cards/product_cards/knowledge_panels/knowledge_panel_summary_card.dart b/packages/smooth_app/lib/cards/product_cards/knowledge_panels/knowledge_panel_summary_card.dart index 42d72dc98e4..eafe9502c03 100644 --- a/packages/smooth_app/lib/cards/product_cards/knowledge_panels/knowledge_panel_summary_card.dart +++ b/packages/smooth_app/lib/cards/product_cards/knowledge_panels/knowledge_panel_summary_card.dart @@ -15,20 +15,11 @@ class KnowledgePanelSummaryCard extends StatelessWidget { if (knowledgePanel.titleElement == null) { return EMPTY_WIDGET; } - final ThemeData themeData = Theme.of(context); switch (knowledgePanel.titleElement!.type) { case TitleElementType.GRADE: return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Padding( - padding: const EdgeInsets.symmetric(vertical: VERY_SMALL_SPACE), - child: Text( - knowledgePanel.topics!.first.substring(0, 1).toUpperCase() + - knowledgePanel.topics!.first.substring(1), - style: themeData.textTheme.headline3, - ), - ), ScoreCard( iconUrl: knowledgePanel.titleElement!.iconUrl, description: knowledgePanel.titleElement!.title, diff --git a/packages/smooth_app/lib/cards/product_cards/knowledge_panels/knowledge_panels_builder.dart b/packages/smooth_app/lib/cards/product_cards/knowledge_panels/knowledge_panels_builder.dart index 7898a00aa75..4ded04be552 100644 --- a/packages/smooth_app/lib/cards/product_cards/knowledge_panels/knowledge_panels_builder.dart +++ b/packages/smooth_app/lib/cards/product_cards/knowledge_panels/knowledge_panels_builder.dart @@ -7,6 +7,7 @@ import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:provider/provider.dart'; import 'package:smooth_app/cards/product_cards/knowledge_panels/knowledge_panel_element_card.dart'; import 'package:smooth_app/data_models/user_preferences.dart'; +import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/helpers/product_cards_helper.dart'; import 'package:smooth_app/pages/product/edit_ingredients_page.dart'; import 'package:smooth_app/pages/product/nutrition_page_loaded.dart'; @@ -65,8 +66,9 @@ class KnowledgePanelsBuilder { /// Typical use case so far: onboarding, where we focus on one panel only. Widget? buildSingle( final KnowledgePanels knowledgePanels, - final String panelId, - ) { + final String panelId, { + final BuildContext? context, + }) { if (knowledgePanels.panelIdToPanelMap['root'] == null) { return null; } @@ -81,7 +83,11 @@ class KnowledgePanelsBuilder { if (panelId != panelElement.panelElement!.panelId) { continue; } - return _buildPanel(panelElement, knowledgePanels); + return _buildPanel( + panelElement, + knowledgePanels, + context: context, + ); } return null; } @@ -97,6 +103,15 @@ class KnowledgePanelsBuilder { knowledgePanels.panelIdToPanelMap[panelId]!; // [knowledgePanelElementWidgets] are a set of widgets inside the root panel. final List knowledgePanelElementWidgets = []; + if (context != null) { + knowledgePanelElementWidgets.add(Padding( + padding: const EdgeInsets.symmetric(vertical: VERY_SMALL_SPACE), + child: Text( + rootPanel.titleElement!.title, + style: Theme.of(context).textTheme.headline3, + ), + )); + } for (final KnowledgePanelElement knowledgePanelElement in rootPanel.elements ?? []) { knowledgePanelElementWidgets.add(KnowledgePanelElementCard( diff --git a/packages/smooth_app/lib/pages/onboarding/knowledge_panel_page_template.dart b/packages/smooth_app/lib/pages/onboarding/knowledge_panel_page_template.dart index 412afb5c61d..7a9bcaf26b0 100644 --- a/packages/smooth_app/lib/pages/onboarding/knowledge_panel_page_template.dart +++ b/packages/smooth_app/lib/pages/onboarding/knowledge_panel_page_template.dart @@ -70,6 +70,7 @@ class _KnowledgePanelPageTemplateState const KnowledgePanelsBuilder().buildSingle( _knowledgePanels, widget.panelId, + context: context, )!; return Scaffold( body: Stack(