Im trying to convert a hex color to a const Color to be used in MaterialColor. Im not sure how to setup the factory, so the class can return a const Color. My class:
class HtmlColor extends Color {
factory HtmlColor(String hexCode, int amt) {
if (hexCode[0] == "#") {
hexCode = hexCode.substring(1, 7);
}
var num = int.parse(hexCode, radix: 16);
var r = (num >> 16) + amt;
if (r > 255) r = 255;
else if (r < 0) r = 0;
var b = ((num >> 8) & 0x00FF) + amt;
if (b > 255) b = 255;
else if (b < 0) b = 0;
var g = (num & 0x0000FF) + amt;
if (g > 255) g = 255;
else if (g < 0) g = 0;
return new HtmlColor.fromValue((g | (b << 8) | (r << 16)) + 0xFF000000);
}
const HtmlColor.fromValue(int value) : super(value);
}