File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,14 +26,27 @@ class ColorUtils {
2626 /// Convert into bbcode recognized color.
2727 static String toBBCodeColor (String color, {bool useHex = true }) {
2828 // Try use named color first.
29- final colorValue = int .tryParse (color.substring (1 ), radix: 16 );
29+ int ? colorValue;
30+
31+ if (color.startsWith ('#' )) {
32+ colorValue = int .tryParse (color.substring (1 ), radix: 16 );
33+ } else {
34+ colorValue = int .tryParse (color, radix: 16 );
35+ }
36+
3037 final WebColors webColor;
3138 if (colorValue != null ) {
39+ // WebColors all have alpha value, append the same value if not have it.
40+ if (colorValue < 0xFF000000 ) {
41+ colorValue += 0xFF000000 ;
42+ }
3243 webColor = WebColors .values.firstWhereOrNull ((e) => e.colorValue == colorValue) ?? WebColors .fromString (color);
3344 } else {
3445 webColor = WebColors .fromString (color);
3546 }
3647
48+ print ('>>> WEB COLOR: $color => $webColor ' );
49+
3750 if (webColor.isValid) {
3851 return '${webColor .name [0 ].toUpperCase ()}${webColor .name .substring (1 )}' ;
3952 }
You can’t perform that action at this time.
0 commit comments