07-21-2023, 09:02 PM
Thanks for asking this question, simples solution is as:
**// Color to Hex String**
colorToHexString(Color color) {
return '#FF${color.value.toRadixString(16).substring(2, 8)}';
}
**// Hex String to Color**
hexStringToColor(String hexColor) {
hexColor = hexColor.toUpperCase().replaceAll("#", "");
if (hexColor.length == 6) {
hexColor = "FF" + hexColor;
}
return Color(int.parse(hexColor, radix: 16));
}
**// How to call function**
String hexCode = colorToHexString(Colors.green);
Color bgColor = hexStringToColor(hexCode);
print("$hexCode = $bgColor");
Enjoy code and help others :)
**// Color to Hex String**
colorToHexString(Color color) {
return '#FF${color.value.toRadixString(16).substring(2, 8)}';
}
**// Hex String to Color**
hexStringToColor(String hexColor) {
hexColor = hexColor.toUpperCase().replaceAll("#", "");
if (hexColor.length == 6) {
hexColor = "FF" + hexColor;
}
return Color(int.parse(hexColor, radix: 16));
}
**// How to call function**
String hexCode = colorToHexString(Colors.green);
Color bgColor = hexStringToColor(hexCode);
print("$hexCode = $bgColor");
Enjoy code and help others :)