toColor method
16进制颜色
Implementation
Color toColor(){
// String hex = this.replaceAll('#', '');
// int count = 0;
// switch (hex.length) {
// case 3: // #RGB
// case 4: // #ARGB
// count = 1;
// break;
// case 6: // #RRGGBB
// case 8: // #AARRGGBB
// count = 2;
// break;
// default: // 默认颜色
// return Colors.transparent;
// break;
// }
// List temp = [];
// for (int i = 0; i < hex.length; i += count) {
// String str = hex.substring(i, i + count);
// temp.add(int.parse(str, radix: 16));
// }
// if (temp.length == 3) {
// temp.insert(0, 255);
// }
// return Color.fromRGBO(temp[1], temp[2], temp[3], temp[0] / 255.0);
String hexColor = this.toUpperCase().replaceAll("#", "");
if (hexColor.length == 6) {
hexColor = "FF" + hexColor;
}
return Color(int.parse(hexColor, radix: 16));
}