DEV Community

Discussion on: How to use hexadecimal colour strings in Flutter

Collapse
 
aboutandre profile image
aboutandre

Hey @mightytechno ,
I am just learning Flutter. So maybe this is not so good.
But Android Studio was complaining that there was no return value:

  • info: This function has a return type of 'Color', but doesn't end with a return statement.

So I wrote like this:

Color colorConvert(String color) {
  color = color.replaceAll("#", "");
  var converted;
  if (color.length == 6) {
    converted = Color(int.parse("0xFF" + color));
  } else if (color.length == 8) {
    converted = Color(int.parse("0x" + color));
  }
  return converted;
}