Skip to content

Commit df7d9d7

Browse files
authored
feat: Indicator color for Health and Environment tabs (#6715)
* Indicator color for Health and Environment tabs * One missing file
1 parent 692610c commit df7d9d7

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

packages/smooth_app/lib/knowledge_panel/knowledge_panels_builder.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ class KnowledgePanelsBuilder {
3434
: getKnowledgePanel(product, panelId);
3535
final List<Widget> children = <Widget>[];
3636
if (rootPanel != null) {
37-
children.add(KnowledgePanelTitle(title: rootPanel.titleElement!.title));
37+
children.add(
38+
KnowledgePanelTitle(
39+
title: rootPanel.titleElement!.title,
40+
topics: rootPanel.topics,
41+
),
42+
);
3843
if (rootPanel.elements != null) {
3944
for (int i = 0; i < rootPanel.elements!.length; i++) {
4045
final KnowledgePanelElement element = rootPanel.elements![i];
@@ -331,9 +336,10 @@ class KnowledgePanelsBuilder {
331336
}
332337

333338
class KnowledgePanelTitle extends StatelessWidget {
334-
const KnowledgePanelTitle({required this.title, super.key});
339+
const KnowledgePanelTitle({required this.title, this.topics, super.key});
335340

336341
final String title;
342+
final List<String>? topics;
337343

338344
@override
339345
Widget build(BuildContext context) {

packages/smooth_app/lib/pages/product/product_page/header/product_page_tabs.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import 'package:flutter/material.dart';
22
import 'package:openfoodfacts/openfoodfacts.dart';
33
import 'package:provider/provider.dart';
4+
import 'package:smooth_app/cards/data_cards/score_card.dart';
45
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
6+
import 'package:smooth_app/helpers/product_cards_helper.dart';
7+
import 'package:smooth_app/helpers/score_card_helper.dart';
58
import 'package:smooth_app/knowledge_panel/knowledge_panels_builder.dart';
69
import 'package:smooth_app/l10n/app_localizations.dart';
710
import 'package:smooth_app/pages/folksonomy/folksonomy_card.dart';
811
import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart';
912
import 'package:smooth_app/pages/prices/prices_card.dart';
1013
import 'package:smooth_app/pages/product/website_card.dart';
14+
import 'package:smooth_app/widgets/smooth_circle.dart';
1115
import 'package:smooth_app/widgets/smooth_tabbar.dart';
1216

1317
enum ProductPageHarcodedTabs {
@@ -27,11 +31,13 @@ class ProductPageTab {
2731
required this.id,
2832
required this.labelBuilder,
2933
required this.builder,
34+
this.prefix,
3035
});
3136

3237
final String id;
3338
final String Function(BuildContext) labelBuilder;
3439
final Widget Function(BuildContext, Product) builder;
40+
final Widget? prefix;
3541
}
3642

3743
class ProductPageTabBar extends StatelessWidget {
@@ -56,6 +62,9 @@ class ProductPageTabBar extends StatelessWidget {
5662
);
5763
})
5864
.toList(growable: false),
65+
leadingItems: tabs
66+
.map((ProductPageTab tab) => tab.prefix)
67+
.toList(growable: false),
5968
onTabChanged: (_) {},
6069
),
6170
),
@@ -98,6 +107,7 @@ class ProductPageTabBar extends StatelessWidget {
98107
ProductPageTab(
99108
id: id,
100109
labelBuilder: (_) => knowledgePanelTitle.title,
110+
prefix: _extractPrefix(product, knowledgePanelTitle),
101111
builder: (_, _) => ListView.builder(
102112
padding: EdgeInsetsDirectional.zero,
103113
itemCount: children.length - 1,
@@ -189,6 +199,32 @@ class ProductPageTabBar extends StatelessWidget {
189199

190200
return tabs;
191201
}
202+
203+
static Widget? _extractPrefix(Product product, KnowledgePanelTitle title) {
204+
final String? attribute = switch (title.topics?.firstOrNull) {
205+
'health' => Attribute.ATTRIBUTE_NUTRISCORE,
206+
'environment' => Attribute.ATTRIBUTE_ECOSCORE,
207+
_ => null,
208+
};
209+
210+
if (attribute == null) {
211+
return null;
212+
}
213+
214+
final List<Attribute> attributes = getPopulatedAttributes(product, <String>[
215+
attribute,
216+
], <String>[]);
217+
218+
if (attributes.isEmpty) {
219+
return null;
220+
}
221+
222+
final CardEvaluation eval = getCardEvaluationFromAttribute(
223+
attributes.first,
224+
);
225+
226+
return SmoothCircle.indicator(color: eval.textColor, size: 15.0);
227+
}
192228
}
193229

194230
class _TabBarDelegate extends SliverPersistentHeaderDelegate {

packages/smooth_app/lib/themes/smooth_theme_colors.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class SmoothColorsThemeExtension
99
required this.primarySemiDark,
1010
required this.primaryTone,
1111
required this.primaryNormal,
12+
required this.primaryAccent,
1213
required this.primaryMedium,
1314
required this.primaryLight,
1415
required this.secondaryNormal,
@@ -34,6 +35,7 @@ class SmoothColorsThemeExtension
3435
primaryDark = const Color(0xFF483527),
3536
primarySemiDark = const Color(0xFF52443D),
3637
primaryTone = const Color(0xFF81756C),
38+
primaryAccent = const Color(0xFF875737),
3739
primaryNormal = const Color(0xFFA08D84),
3840
primaryMedium = const Color(0xFFEDE0DB),
3941
primaryLight = const Color(0xFFF6F3F0),
@@ -70,6 +72,7 @@ class SmoothColorsThemeExtension
7072

7173
// Macchiato
7274
final Color primaryNormal;
75+
final Color primaryAccent;
7376

7477
// Cappuccino
7578
final Color primaryMedium;
@@ -103,6 +106,7 @@ class SmoothColorsThemeExtension
103106
Color? primarySemiDark,
104107
Color? primaryTone,
105108
Color? primaryNormal,
109+
Color? primaryAccent,
106110
Color? primaryMedium,
107111
Color? primaryLight,
108112
Color? secondaryNormal,
@@ -128,6 +132,7 @@ class SmoothColorsThemeExtension
128132
primarySemiDark: primarySemiDark ?? this.primarySemiDark,
129133
primaryTone: primaryTone ?? this.primaryTone,
130134
primaryNormal: primaryNormal ?? this.primaryNormal,
135+
primaryAccent: primaryAccent ?? this.primaryAccent,
131136
primaryMedium: primaryMedium ?? this.primaryMedium,
132137
primaryLight: primaryLight ?? this.primaryLight,
133138
secondaryNormal: secondaryNormal ?? this.secondaryNormal,
@@ -168,6 +173,7 @@ class SmoothColorsThemeExtension
168173
primarySemiDark: Color.lerp(primarySemiDark, other.primarySemiDark, t)!,
169174
primaryTone: Color.lerp(primaryTone, other.primaryTone, t)!,
170175
primaryNormal: Color.lerp(primaryNormal, other.primaryNormal, t)!,
176+
primaryAccent: Color.lerp(primaryAccent, other.primaryAccent, t)!,
171177
primaryMedium: Color.lerp(primaryMedium, other.primaryMedium, t)!,
172178
primaryLight: Color.lerp(primaryLight, other.primaryLight, t)!,
173179
secondaryNormal: Color.lerp(secondaryNormal, other.secondaryNormal, t)!,

packages/smooth_app/lib/widgets/smooth_circle.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ class SmoothCircle extends StatelessWidget {
99
super.key,
1010
});
1111

12+
SmoothCircle.indicator({
13+
required this.color,
14+
required double size,
15+
this.padding = EdgeInsetsDirectional.zero,
16+
}) : assert(size > 0.0),
17+
child = SizedBox.square(dimension: size);
18+
1219
final EdgeInsetsGeometry padding;
1320
final Color color;
1421
final Widget child;

0 commit comments

Comments
 (0)