Skip to content

Commit 637cd4b

Browse files
RZEROSTERNCopilot
andauthored
Update lib/src/presentation/utils/html_style_builder.dart
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2df7471 commit 637cd4b

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

lib/src/presentation/utils/html_style_builder.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)