File tree Expand file tree Collapse file tree
lib/src/presentation/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,7 +37,27 @@ class HtmlStyleBuilder {
3737 }
3838
3939 static Color _parseColor (String hex) {
40+ // Remove leading '#' characters, if any.
4041 final code = hex.replaceAll ('#' , '' );
41- return Color (int .parse (code, radix: 16 ));
42+
43+ // Normalize to 8-digit ARGB. Accept 6-digit RGB or 8-digit ARGB; otherwise fallback.
44+ String normalized;
45+ if (code.length == 6 ) {
46+ // Treat 6-digit RGB as fully opaque.
47+ normalized = 'FF$code ' ;
48+ } else if (code.length == 8 ) {
49+ normalized = code;
50+ } else {
51+ // Invalid length, use a safe fallback color.
52+ return const Color (0xFF000000 );
53+ }
54+
55+ final value = int .tryParse (normalized, radix: 16 );
56+ if (value == null ) {
57+ // Invalid hex characters, use a safe fallback color.
58+ return const Color (0xFF000000 );
59+ }
60+
61+ return Color (value);
4262 }
4363}
You can’t perform that action at this time.
0 commit comments