Skip to content

Commit

Permalink
fix: #2530 - replaced the score colors with a score emoji (#2569)
Browse files Browse the repository at this point in the history
* fix: #2530 - replaced the score colors with a score emoji

Impacted file:
* `knowledge_panel_title_card.dart`: replaced the score colors with a score emoji as a test, with a simple way to roll back to the previous version for comparison purposes

* fix: #2530 - to the "new" mode

Impacted file:
* `knowledge_panel_title_card.dart`

* fix: #2530 - dev mode settings and new emoji

Impacted files:
* `knowledge_panel_title_card.dart`: now using preferences; new emoji
* `user_preferences_dev_mode.dart`: 2 new settings/preferences - emoji, and no color

* fix: #2530 - replaced String emoji with IconData

Impacted file:
* `knowledge_panel_title_card.dart`: replaced `String` emoji with `IconData`
  • Loading branch information
monsieurtanuki authored Jul 21, 2022
1 parent 01f1b89 commit a1e096c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:flutter/material.dart';
import 'package:openfoodfacts/model/KnowledgePanel.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/cards/category_cards/abstract_cache.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
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';

class KnowledgePanelTitleCard extends StatelessWidget {
Expand All @@ -19,13 +22,24 @@ class KnowledgePanelTitleCard extends StatelessWidget {

@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
final UserPreferences userPreferences = context.watch<UserPreferences>();
Color? colorFromEvaluation;
if (knowledgePanelTitleElement.iconColorFromEvaluation ?? false) {
if (themeData.brightness == Brightness.dark) {
colorFromEvaluation = _getColorFromEvaluationDarkMode(evaluation);
} else {
colorFromEvaluation = _getColorFromEvaluation(evaluation);
IconData? iconData;
if (userPreferences.getFlag(
UserPreferencesDevMode.userPreferencesFlagAccessibilityEmoji) ??
false) {
iconData = _getIconDataFromEvaluation(evaluation);
}
if (!(userPreferences.getFlag(
UserPreferencesDevMode.userPreferencesFlagAccessibilityNoColor) ??
false)) {
final ThemeData themeData = Theme.of(context);
if (knowledgePanelTitleElement.iconColorFromEvaluation ?? false) {
if (themeData.brightness == Brightness.dark) {
colorFromEvaluation = _getColorFromEvaluationDarkMode(evaluation);
} else {
colorFromEvaluation = _getColorFromEvaluation(evaluation);
}
}
}
List<Widget> iconWidget;
Expand All @@ -45,6 +59,11 @@ class KnowledgePanelTitleCard extends StatelessWidget {
const Padding(
padding: EdgeInsetsDirectional.only(start: SMALL_SPACE),
),
if (iconData != null)
Padding(
padding: const EdgeInsetsDirectional.only(end: SMALL_SPACE),
child: Icon(iconData),
),
];
} else {
iconWidget = <Widget>[];
Expand Down Expand Up @@ -118,4 +137,19 @@ class KnowledgePanelTitleCard extends StatelessWidget {
return LIGHT_GREY_COLOR;
}
}

IconData? _getIconDataFromEvaluation(Evaluation? evaluation) {
switch (evaluation) {
case Evaluation.BAD:
return Icons.sentiment_very_dissatisfied;
case Evaluation.AVERAGE:
return Icons.sentiment_satisfied;
case Evaluation.GOOD:
return Icons.sentiment_very_satisfied;
case null:
case Evaluation.NEUTRAL:
case Evaluation.UNKNOWN:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
static const String userPreferencesAppLanguageCode = '__appLanguage';
static const String userPreferencesCameraPostFrameDuration =
'__cameraPostFrameDuration';
static const String userPreferencesFlagAccessibilityNoColor =
'__accessibilityNoColor';
static const String userPreferencesFlagAccessibilityEmoji =
'__accessibilityEmoji';

final TextEditingController _textFieldController = TextEditingController();

Expand Down Expand Up @@ -164,6 +168,32 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
_showSuccessMessage();
},
),
SwitchListTile(
title: const Text(
'Accessibility: remove colors',
),
value: userPreferences
.getFlag(userPreferencesFlagAccessibilityNoColor) ??
false,
onChanged: (bool value) async {
await userPreferences.setFlag(
userPreferencesFlagAccessibilityNoColor, value);
_showSuccessMessage();
},
),
SwitchListTile(
title: const Text(
'Accessibility: show emoji',
),
value:
userPreferences.getFlag(userPreferencesFlagAccessibilityEmoji) ??
false,
onChanged: (bool value) async {
await userPreferences.setFlag(
userPreferencesFlagAccessibilityEmoji, value);
_showSuccessMessage();
},
),
ListTile(
title: Text(
appLocalizations.dev_preferences_export_history_title,
Expand Down

0 comments on commit a1e096c

Please sign in to comment.