Skip to content

Commit c3a2d32

Browse files
committed
Fix uppercase hex codes not working and add support for hex codes with alpha
1 parent 24bd197 commit c3a2d32

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/src/css_parser.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,14 +844,15 @@ class ExpressionMapping {
844844
var text = _text.replaceFirst('#', '');
845845
if (text.length == 3)
846846
text = text.replaceAllMapped(
847-
RegExp(r"[a-f]|\d"), (match) => '${match.group(0)}${match.group(0)}');
848-
int color = int.parse(text, radix: 16);
849-
850-
if (color <= 0xffffff) {
851-
return new Color(color).withAlpha(255);
847+
RegExp(r"[a-f]|\d", caseSensitive: false),
848+
(match) => '${match.group(0)}${match.group(0)}'
849+
);
850+
if (text.length > 6) {
851+
text = "0x" + text;
852852
} else {
853-
return new Color(color);
853+
text = "0xFF" + text;
854854
}
855+
return new Color(int.parse(text));
855856
}
856857

857858
static Color? rgbOrRgbaToColor(String text) {

0 commit comments

Comments
 (0)