Skip to content

Commit

Permalink
fix: KP UI improvements (font size/font height…) (#6155)
Browse files Browse the repository at this point in the history
* KP improvements

(cherry picked from commit 9506642832d82356a8ab717de5d07e3273e73cfe)

* Use the correct variant of the SVG

* Improve normal text in dark mode
  • Loading branch information
g123k authored Jan 8, 2025
1 parent 5186bc6 commit d389367
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 26 deletions.
17 changes: 17 additions & 0 deletions packages/smooth_app/assets/cache/off-logo-icon-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_expanded_card.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels_builder.dart';
import 'package:smooth_app/pages/product/common/product_refresher.dart';
import 'package:smooth_app/pages/product/product_field_editor.dart';
import 'package:smooth_app/pages/scan/carousel/scan_carousel_manager.dart';
import 'package:smooth_app/themes/smooth_theme.dart';
import 'package:smooth_app/themes/smooth_theme_colors.dart';
Expand Down Expand Up @@ -45,7 +46,8 @@ class _KnowledgePanelPageState extends State<KnowledgePanelPage>
}

static KnowledgePanelPanelGroupElement? _groupElementOf(
BuildContext context) {
BuildContext context,
) {
try {
return Provider.of<KnowledgePanelPanelGroupElement>(context);
} catch (_) {
Expand Down Expand Up @@ -78,6 +80,7 @@ class _KnowledgePanelPageState extends State<KnowledgePanelPage>
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
actions: _actions(),
),
body: RefreshIndicator(
onRefresh: () => _refreshProduct(context),
Expand All @@ -88,19 +91,25 @@ class _KnowledgePanelPageState extends State<KnowledgePanelPage>
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
padding: const EdgeInsetsDirectional.only(
bottom: SMALL_SPACE,
top: SMALL_SPACE,
),
child: SmoothCard(
padding: const EdgeInsets.all(
SMALL_SPACE,
padding: const EdgeInsetsDirectional.only(
top: SMALL_SPACE,
start: SMALL_SPACE,
end: SMALL_SPACE,
bottom: LARGE_SPACE,
),
child: KnowledgePanelExpandedCard(
panelId: widget.panelId,
product: upToDateProduct,
isInitiallyExpanded: true,
isClickable: true,
child: DefaultTextStyle.merge(
style: const TextStyle(fontSize: 15.0, height: 1.5),
child: KnowledgePanelExpandedCard(
panelId: widget.panelId,
product: upToDateProduct,
isInitiallyExpanded: true,
isClickable: true,
),
),
),
),
Expand Down Expand Up @@ -164,6 +173,24 @@ class _KnowledgePanelPageState extends State<KnowledgePanelPage>
}
}

// TODO(g123k): Improve this mechanism to be more flexible
List<Widget>? _actions() {
if (widget.panelId == 'ingredients') {
return <Widget>[
IconButton(
onPressed: () async => ProductFieldOcrIngredientEditor().edit(
context: context,
product: upToDateProduct,
),
icon: const Icon(Icons.edit),
tooltip: AppLocalizations.of(context).ingredients_editing_title,
),
];
}

return null;
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class KnowledgePanelTextCard extends StatelessWidget {
final Widget text = MergeSemantics(
child: SmoothHtmlWidget(
textElement.html,
textStyle: WellSpacedTextHelper.TEXT_STYLE_WITH_WELL_SPACED,
textStyle: WellSpacedTextHelper.TEXT_STYLE_WITH_WELL_SPACED.copyWith(
fontSize: 15.0,
),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:smooth_app/helpers/extension_on_text_helper.dart';
import 'package:smooth_app/helpers/ui_helpers.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart';
import 'package:smooth_app/themes/constant_icons.dart';
import 'package:smooth_app/themes/theme_provider.dart';
import 'package:smooth_app/widgets/smooth_text.dart';

class KnowledgePanelTitleCard extends StatelessWidget {
Expand All @@ -36,9 +37,8 @@ class KnowledgePanelTitleCard extends StatelessWidget {
if (!(userPreferences.getFlag(
UserPreferencesDevMode.userPreferencesFlagAccessibilityNoColor) ??
false)) {
final ThemeData themeData = Theme.of(context);
if (knowledgePanelTitleElement.iconColorFromEvaluation ?? false) {
if (themeData.brightness == Brightness.dark) {
if (context.darkTheme()) {
colorFromEvaluation = _getColorFromEvaluationDarkMode(evaluation);
} else {
colorFromEvaluation = _getColorFromEvaluation(evaluation);
Expand All @@ -52,9 +52,12 @@ class KnowledgePanelTitleCard extends StatelessWidget {
flex: IconWidgetSizer.getIconFlex(),
child: Center(
child: AbstractCache.best(
iconUrl: knowledgePanelTitleElement.iconUrl,
width: 36,
height: 36,
iconUrl: _rewriteIconUrl(
context,
knowledgePanelTitleElement.iconUrl,
),
width: 36.0,
height: 36.0,
color: colorFromEvaluation,
),
),
Expand Down Expand Up @@ -88,24 +91,38 @@ class KnowledgePanelTitleCard extends StatelessWidget {
flex: IconWidgetSizer.getRemainingWidgetFlex(),
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
final bool hasSubtitle =
knowledgePanelTitleElement.subtitle != null;

return Wrap(
direction: Axis.vertical,
children: <Widget>[
SizedBox(
width: constraints.maxWidth,
child: Text(
knowledgePanelTitleElement.title,
style: TextStyle(color: colorFromEvaluation),
style: TextStyle(
color: colorFromEvaluation,
fontSize: hasSubtitle ? 15.5 : 15.0,
fontWeight: hasSubtitle
? FontWeight.w500
: FontWeight.normal,
),
),
),
if (knowledgePanelTitleElement.subtitle != null)
SizedBox(
width: constraints.maxWidth,
child: Text(
knowledgePanelTitleElement.subtitle!,
style: WellSpacedTextHelper
.TEXT_STYLE_WITH_WELL_SPACED,
).selectable(isSelectable: !isClickable),
if (hasSubtitle)
Padding(
padding: const EdgeInsetsDirectional.only(
top: VERY_SMALL_SPACE,
),
child: SizedBox(
width: constraints.maxWidth,
child: Text(
knowledgePanelTitleElement.subtitle!,
style: WellSpacedTextHelper
.TEXT_STYLE_WITH_WELL_SPACED,
).selectable(isSelectable: !isClickable),
),
),
],
);
Expand Down Expand Up @@ -145,7 +162,7 @@ class KnowledgePanelTitleCard extends StatelessWidget {
case null:
case Evaluation.NEUTRAL:
case Evaluation.UNKNOWN:
return LIGHT_GREY_COLOR;
return Colors.white;
}
}

Expand Down Expand Up @@ -185,6 +202,18 @@ class KnowledgePanelTitleCard extends StatelessWidget {
return buffer.toString();
}

String? _rewriteIconUrl(BuildContext context, String? iconUrl) {
final bool lightTheme = context.lightTheme();

if (iconUrl ==
'https://static.openfoodfacts.org/images/logos/off-logo-icon-light.svg' &&
!lightTheme) {
return 'https://static.openfoodfacts.org/images/logos/off-logo-icon-dark.svg';
}

return iconUrl;
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/widgets/smooth_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension DefaultTextStyleExtension on DefaultTextStyle {
class WellSpacedTextHelper {
const WellSpacedTextHelper._();

static const double _WELL_SPACED_TEXT_HEIGHT = 1.4;
static const double _WELL_SPACED_TEXT_HEIGHT = 1.45;

static const TextStyle TEXT_STYLE_WITH_WELL_SPACED =
TextStyle(height: _WELL_SPACED_TEXT_HEIGHT);
Expand Down

0 comments on commit d389367

Please sign in to comment.