Skip to content

Commit

Permalink
fix: #1540 - duplicated panel title (#1665)
Browse files Browse the repository at this point in the history
* fix: #1540 - duplicated panel title

* fix: #1540 - refactoring
  • Loading branch information
cli1005 authored Apr 29, 2022
1 parent bcb3b0e commit af7ce55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Widget>[
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand All @@ -81,7 +83,11 @@ class KnowledgePanelsBuilder {
if (panelId != panelElement.panelElement!.panelId) {
continue;
}
return _buildPanel(panelElement, knowledgePanels);
return _buildPanel(
panelElement,
knowledgePanels,
context: context,
);
}
return null;
}
Expand All @@ -97,6 +103,15 @@ class KnowledgePanelsBuilder {
knowledgePanels.panelIdToPanelMap[panelId]!;
// [knowledgePanelElementWidgets] are a set of widgets inside the root panel.
final List<Widget> knowledgePanelElementWidgets = <Widget>[];
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 ?? <KnowledgePanelElement>[]) {
knowledgePanelElementWidgets.add(KnowledgePanelElementCard(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class _KnowledgePanelPageTemplateState
const KnowledgePanelsBuilder().buildSingle(
_knowledgePanels,
widget.panelId,
context: context,
)!;
return Scaffold(
body: Stack(
Expand Down

0 comments on commit af7ce55

Please sign in to comment.