-
-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact: score card refactoring (#3961)
Impacted files: * `attributes_card_helper.dart`: refactor as advanced `enum` from `score_card_helper.dart` * `knowledge_panel_summary_card.dart`: now using the new `ScoreCard.titleElement` constructor * `score_card.dart`: refactored `CardEvaluation` as advanced `enum` from `score_card_helper.dart`; refactored `ScoreCard` with 2 explicit constructors instead of a single nameless one * `score_card_helper.dart`: refactored `enum`s and moved code to more relevant files * `summary_card.dart`: now using the new `ScoreCard.attribute` constructor
- Loading branch information
1 parent
72e98df
commit 12a561a
Showing
5 changed files
with
100 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,32 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:smooth_app/cards/data_cards/score_card.dart'; | ||
import 'package:smooth_app/generic_lib/design_constants.dart'; | ||
import 'package:smooth_app/helpers/attributes_card_helper.dart'; | ||
|
||
Color getBackgroundColor(CardEvaluation evaluation) { | ||
switch (evaluation) { | ||
case CardEvaluation.UNKNOWN: | ||
return GREY_COLOR; | ||
case CardEvaluation.VERY_BAD: | ||
return RED_BACKGROUND_COLOR; | ||
case CardEvaluation.BAD: | ||
return ORANGE_BACKGROUND_COLOR; | ||
case CardEvaluation.NEUTRAL: | ||
return YELLOW_BACKGROUND_COLOR; | ||
case CardEvaluation.GOOD: | ||
return LIGHT_GREEN_BACKGROUND_COLOR; | ||
case CardEvaluation.VERY_GOOD: | ||
return DARK_GREEN_BACKGROUND_COLOR; | ||
} | ||
} | ||
|
||
Color getBackgroundColorFromAttribute(Attribute attribute) { | ||
return getBackgroundColor(getCardEvaluationFromAttribute(attribute)); | ||
} | ||
|
||
Color getTextColor(CardEvaluation evaluation) { | ||
switch (evaluation) { | ||
case CardEvaluation.UNKNOWN: | ||
return PRIMARY_GREY_COLOR; | ||
case CardEvaluation.VERY_BAD: | ||
return RED_COLOR; | ||
case CardEvaluation.BAD: | ||
return LIGHT_ORANGE_COLOR; | ||
case CardEvaluation.NEUTRAL: | ||
return DARK_YELLOW_COLOR; | ||
case CardEvaluation.GOOD: | ||
return LIGHT_GREEN_COLOR; | ||
case CardEvaluation.VERY_GOOD: | ||
return DARK_GREEN_COLOR; | ||
} | ||
CardEvaluation getCardEvaluationFromAttribute(Attribute attribute) { | ||
return getAttributeEvaluation(attribute).getCardEvaluation(); | ||
} | ||
|
||
CardEvaluation getCardEvaluationFromAttribute(Attribute attribute) { | ||
switch (getAttributeEvaluation(attribute)) { | ||
case AttributeEvaluation.UNKNOWN: | ||
return CardEvaluation.UNKNOWN; | ||
case AttributeEvaluation.VERY_BAD: | ||
return CardEvaluation.VERY_BAD; | ||
case AttributeEvaluation.BAD: | ||
return CardEvaluation.BAD; | ||
case AttributeEvaluation.NEUTRAL: | ||
return CardEvaluation.NEUTRAL; | ||
case AttributeEvaluation.GOOD: | ||
return CardEvaluation.GOOD; | ||
case AttributeEvaluation.VERY_GOOD: | ||
return CardEvaluation.VERY_GOOD; | ||
extension GradeExtension on Grade? { | ||
CardEvaluation getCardEvaluation() { | ||
switch (this) { | ||
case Grade.E: | ||
return CardEvaluation.VERY_BAD; | ||
case Grade.D: | ||
return CardEvaluation.BAD; | ||
case Grade.C: | ||
return CardEvaluation.NEUTRAL; | ||
case Grade.B: | ||
return CardEvaluation.GOOD; | ||
case Grade.A: | ||
return CardEvaluation.VERY_GOOD; | ||
case null: | ||
case Grade.UNKNOWN: | ||
return CardEvaluation.UNKNOWN; | ||
} | ||
} | ||
} | ||
|
||
CardEvaluation getCardEvaluationFromKnowledgePanelTitleElement( | ||
TitleElement titleElement) { | ||
switch (titleElement.grade) { | ||
case Grade.E: | ||
return CardEvaluation.VERY_BAD; | ||
case Grade.D: | ||
return CardEvaluation.BAD; | ||
case Grade.C: | ||
return CardEvaluation.NEUTRAL; | ||
case Grade.B: | ||
return CardEvaluation.GOOD; | ||
case Grade.A: | ||
return CardEvaluation.VERY_GOOD; | ||
case null: | ||
case Grade.UNKNOWN: | ||
return CardEvaluation.UNKNOWN; | ||
} | ||
} | ||
TitleElement titleElement, | ||
) => | ||
titleElement.grade.getCardEvaluation(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters