Created
February 28, 2020 14:49
-
-
Save oohyugi/d0bf40555f39f763a5e9f36afe06f1e2 to your computer and use it in GitHub Desktop.
Color from string for flutter app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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