@@ -8,70 +8,72 @@ import 'package:flutter_html/style.dart';
88Style declarationsToStyle (Map <String ?, List <css.Expression >> declarations) {
99 Style style = new Style ();
1010 declarations.forEach ((property, value) {
11- switch (property) {
12- case 'background-color' :
13- style.backgroundColor = ExpressionMapping .expressionToColor (value.first) ?? style.backgroundColor;
14- break ;
15- case 'color' :
16- style.color = ExpressionMapping .expressionToColor (value.first) ?? style.color;
17- break ;
18- case 'direction' :
19- style.direction = ExpressionMapping .expressionToDirection (value.first);
20- break ;
21- case 'display' :
22- style.display = ExpressionMapping .expressionToDisplay (value.first);
23- break ;
24- case 'line-height' :
25- style.lineHeight = ExpressionMapping .expressionToLineHeight (value.first);
26- break ;
27- case 'font-family' :
28- style.fontFamily = ExpressionMapping .expressionToFontFamily (value.first) ?? style.fontFamily;
29- break ;
30- case 'font-feature-settings' :
31- style.fontFeatureSettings = ExpressionMapping .expressionToFontFeatureSettings (value);
32- break ;
33- case 'font-size' :
34- style.fontSize = ExpressionMapping .expressionToFontSize (value.first) ?? style.fontSize;
35- break ;
36- case 'font-style' :
37- style.fontStyle = ExpressionMapping .expressionToFontStyle (value.first);
38- break ;
39- case 'font-weight' :
40- style.fontWeight = ExpressionMapping .expressionToFontWeight (value.first);
41- break ;
42- case 'text-align' :
43- style.textAlign = ExpressionMapping .expressionToTextAlign (value.first);
44- break ;
45- case 'text-decoration' :
46- List <css.LiteralTerm ?>? textDecorationList = value.whereType< css.LiteralTerm > ().toList ();
47- /// 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"
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 );
53- List <css.LiteralTerm ?>? potentialStyles = value.whereType< css.LiteralTerm > ().toList ();
54- /// 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]
55- potentialStyles.removeWhere ((element) => element != null && element.text != "solid"
56- && element.text != "double" && element.text != "dashed" && element.text != "dotted" && element.text != "wavy" );
57- css.LiteralTerm ? textDecorationStyle = potentialStyles.isNotEmpty ? potentialStyles.last : null ;
58- style.textDecoration = ExpressionMapping .expressionToTextDecorationLine (textDecorationList);
59- if (textDecorationColor != null ) style.textDecorationColor = ExpressionMapping .expressionToColor (textDecorationColor)
60- ?? style.textDecorationColor;
61- if (textDecorationStyle != null ) style.textDecorationStyle = ExpressionMapping .expressionToTextDecorationStyle (textDecorationStyle);
62- break ;
63- case 'text-decoration-color' :
64- style.textDecorationColor = ExpressionMapping .expressionToColor (value.first) ?? style.textDecorationColor;
65- break ;
66- case 'text-decoration-line' :
67- style.textDecoration = ExpressionMapping .expressionToTextDecorationLine (value as List <css.LiteralTerm >);
68- break ;
69- case 'text-decoration-style' :
70- style.textDecorationStyle = ExpressionMapping .expressionToTextDecorationStyle (value.first as css.LiteralTerm );
71- break ;
72- case 'text-shadow' :
73- style.textShadow = ExpressionMapping .expressionToTextShadow (value);
74- break ;
11+ if (value.isNotEmpty) {
12+ switch (property) {
13+ case 'background-color' :
14+ style.backgroundColor = ExpressionMapping .expressionToColor (value.first) ?? style.backgroundColor;
15+ break ;
16+ case 'color' :
17+ style.color = ExpressionMapping .expressionToColor (value.first) ?? style.color;
18+ break ;
19+ case 'direction' :
20+ style.direction = ExpressionMapping .expressionToDirection (value.first);
21+ break ;
22+ case 'display' :
23+ style.display = ExpressionMapping .expressionToDisplay (value.first);
24+ break ;
25+ case 'line-height' :
26+ style.lineHeight = ExpressionMapping .expressionToLineHeight (value.first);
27+ break ;
28+ case 'font-family' :
29+ style.fontFamily = ExpressionMapping .expressionToFontFamily (value.first) ?? style.fontFamily;
30+ break ;
31+ case 'font-feature-settings' :
32+ style.fontFeatureSettings = ExpressionMapping .expressionToFontFeatureSettings (value);
33+ break ;
34+ case 'font-size' :
35+ style.fontSize = ExpressionMapping .expressionToFontSize (value.first) ?? style.fontSize;
36+ break ;
37+ case 'font-style' :
38+ style.fontStyle = ExpressionMapping .expressionToFontStyle (value.first);
39+ break ;
40+ case 'font-weight' :
41+ style.fontWeight = ExpressionMapping .expressionToFontWeight (value.first);
42+ break ;
43+ case 'text-align' :
44+ style.textAlign = ExpressionMapping .expressionToTextAlign (value.first);
45+ break ;
46+ case 'text-decoration' :
47+ List <css.LiteralTerm ?>? textDecorationList = value.whereType< css.LiteralTerm > ().toList ();
48+ /// 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]
49+ textDecorationList.removeWhere ((element) => element != null && element.text != "none"
50+ && element.text != "overline" && element.text != "underline" && element.text != "line-through" );
51+ List <css.Expression ?>? nullableList = value;
52+ css.Expression ? textDecorationColor = nullableList.firstWhere (
53+ (css.Expression ? element) => element is css.HexColorTerm || element is css.FunctionTerm , orElse: () => null );
54+ List <css.LiteralTerm ?>? potentialStyles = value.whereType< css.LiteralTerm > ().toList ();
55+ /// 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]
56+ potentialStyles.removeWhere ((element) => element != null && element.text != "solid"
57+ && element.text != "double" && element.text != "dashed" && element.text != "dotted" && element.text != "wavy" );
58+ css.LiteralTerm ? textDecorationStyle = potentialStyles.isNotEmpty ? potentialStyles.last : null ;
59+ style.textDecoration = ExpressionMapping .expressionToTextDecorationLine (textDecorationList);
60+ if (textDecorationColor != null ) style.textDecorationColor = ExpressionMapping .expressionToColor (textDecorationColor)
61+ ?? style.textDecorationColor;
62+ if (textDecorationStyle != null ) style.textDecorationStyle = ExpressionMapping .expressionToTextDecorationStyle (textDecorationStyle);
63+ break ;
64+ case 'text-decoration-color' :
65+ style.textDecorationColor = ExpressionMapping .expressionToColor (value.first) ?? style.textDecorationColor;
66+ break ;
67+ case 'text-decoration-line' :
68+ style.textDecoration = ExpressionMapping .expressionToTextDecorationLine (value as List <css.LiteralTerm >);
69+ break ;
70+ case 'text-decoration-style' :
71+ style.textDecorationStyle = ExpressionMapping .expressionToTextDecorationStyle (value.first as css.LiteralTerm );
72+ break ;
73+ case 'text-shadow' :
74+ style.textShadow = ExpressionMapping .expressionToTextShadow (value);
75+ break ;
76+ }
7577 }
7678 });
7779 return style;
0 commit comments