I am converting a Color to a String. I am then converting the Color to a String. Unfortunately when I want to convert it back into a Color the operation fails:
<
Leveraging the power of Dart extensions we can augment String with a function that returns a Color:
extension ColorExtension on String {
toColor() {
var hexColor = this.replaceAll("#", "");
if (hexColor.length == 6) {
hexColor = "FF" + hexColor;
}
if (hexColor.length == 8) {
return Color(int.parse("0x$hexColor"));
}
}
}
Set a string color code value in the color property.
child: Text("Text Color",
style: TextStyle(
color: '#55B9F4'.toColor(),
),
)