shadeColor static method
Lightens or darkens the given hex
color by the given percent
.
To lighten a color, set the percent
value to > 0.
To darken a color, set the percent
value to < 0.
Will add a # to the hex
string if it is missing.
Implementation
static String shadeColor(String hex, double percent) {
var bC = basicColorsFromHex(hex);
var R = (bC[BASIC_COLOR_RED]! * (100 + percent) / 100).round();
var G = (bC[BASIC_COLOR_GREEN]! * (100 + percent) / 100).round();
var B = (bC[BASIC_COLOR_BLUE]! * (100 + percent) / 100).round();
if (R > 255) {
R = 255;
} else if (R < 0) {
R = 0;
}
if (G > 255) {
G = 255;
} else if (G < 0) {
G = 0;
}
if (B > 255) {
B = 255;
} else if (B < 0) {
B = 0;
}
var RR = ((R.toRadixString(16).length == 1)
? '0' + R.toRadixString(16)
: R.toRadixString(16));
var GG = ((G.toRadixString(16).length == 1)
? '0' + G.toRadixString(16)
: G.toRadixString(16));
var BB = ((B.toRadixString(16).length == 1)
? '0' + B.toRadixString(16)
: B.toRadixString(16));
return '#' + RR + GG + BB;
}