File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -9,10 +9,13 @@ extension HexColor on Color {
9
9
return Color (int .parse (buffer.toString (), radix: 16 ));
10
10
}
11
11
12
+ /// Converts an rgba value (0-255) into a 2-digit Hex code.
13
+ String _hexValue (int rgbaVal) {
14
+ assert (rgbaVal == rgbaVal & 0xFF );
15
+ return rgbaVal.toRadixString (16 ).padLeft (2 , '0' ).toUpperCase ();
16
+ }
17
+
12
18
/// Prefixes a hash sign if [leadingHashSign] is set to `true` (default is `true` ).
13
19
String toHex ({bool leadingHashSign = true }) => '${leadingHashSign ? '#' : '' }'
14
- '${alpha .toRadixString (16 ).padLeft (2 , '0' ).toUpperCase ()}'
15
- '${red .toRadixString (16 ).padLeft (2 , '0' ).toUpperCase ()}'
16
- '${green .toRadixString (16 ).padLeft (2 , '0' ).toUpperCase ()}'
17
- '${blue .toRadixString (16 ).padLeft (2 , '0' ).toUpperCase ()}' ;
20
+ '${_hexValue (alpha )}${_hexValue (red )}${_hexValue (green )}${_hexValue (blue )}' ;
18
21
}
You can’t perform that action at this time.
0 commit comments