Skip to content

Instantly share code, notes, and snippets.

@oohyugi
Created February 28, 2020 14:49
Show Gist options
  • Save oohyugi/d0bf40555f39f763a5e9f36afe06f1e2 to your computer and use it in GitHub Desktop.
Save oohyugi/d0bf40555f39f763a5e9f36afe06f1e2 to your computer and use it in GitHub Desktop.
Color from string for flutter app
class HexColor extends Color {
static int _getColorFromHex(String hexColor) {
hexColor = hexColor.toUpperCase().replaceAll("#", "");
if (hexColor.length == 6) {
hexColor = "FF" + hexColor;
}
return int.parse(hexColor, radix: 16);
}
HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment