Skip to content

Commit e8bb0fd

Browse files
committed
Fix null value issue and improve formatting
1 parent 65e4bc3 commit e8bb0fd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/src/css_parser.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ Style declarationsToStyle(Map<String?, List<css.Expression>> declarations) {
4545
case 'text-decoration':
4646
List<css.LiteralTerm?>? textDecorationList = value.whereType<css.LiteralTerm>().toList();
4747
/// List<css.LiteralTerm> might include other values than the ones we want for [textDecorationList], so make sure to remove those before passing it to [ExpressionMapping]
48-
textDecorationList.removeWhere((element) => element != null && element.text != "none" && element.text != "overline" && element.text != "underline" && element.text != "line-through");
49-
css.Expression textDecorationColor = value.firstWhere((css.Expression? element) => element is css.HexColorTerm || element is css.FunctionTerm,
50-
orElse: () => css.HexColorTerm(null, style.textDecorationColor!.value.toRadixString(16), null));
48+
textDecorationList.removeWhere((element) => element != null && element.text != "none"
49+
&& element.text != "overline" && element.text != "underline" && element.text != "line-through");
50+
List<css.Expression?>? nullableList = value;
51+
css.Expression? textDecorationColor = nullableList.firstWhere(
52+
(css.Expression? element) => element is css.HexColorTerm || element is css.FunctionTerm, orElse: () => null);
5153
List<css.LiteralTerm?>? potentialStyles = value.whereType<css.LiteralTerm>().toList();
5254
/// List<css.LiteralTerm> might include other values than the ones we want for [textDecorationStyle], so make sure to remove those before passing it to [ExpressionMapping]
53-
potentialStyles.removeWhere((element) => element != null && element.text != "solid" && element.text != "double" && element.text != "dashed" && element.text != "dotted" && element.text != "wavy");
55+
potentialStyles.removeWhere((element) => element != null && element.text != "solid"
56+
&& element.text != "double" && element.text != "dashed" && element.text != "dotted" && element.text != "wavy");
5457
css.LiteralTerm? textDecorationStyle = potentialStyles.isNotEmpty ? potentialStyles.last : null;
5558
style.textDecoration = ExpressionMapping.expressionToTextDecorationLine(textDecorationList);
56-
style.textDecorationColor = ExpressionMapping.expressionToColor(textDecorationColor) ?? style.textDecorationColor;
59+
if (textDecorationColor != null) style.textDecorationColor = ExpressionMapping.expressionToColor(textDecorationColor)
60+
?? style.textDecorationColor;
5761
if (textDecorationStyle != null) style.textDecorationStyle = ExpressionMapping.expressionToTextDecorationStyle(textDecorationStyle);
5862
break;
5963
case 'text-decoration-color':

0 commit comments

Comments
 (0)