INNER CODE UNIT · Dart
ColorUtils
Ephenodrom/Dart-Basic-Utils · lib/src/ColorUtils.dart:6
class ColorUtils {
static const String BASIC_COLOR_RED = 'red';
static const String BASIC_COLOR_GREEN = 'green';
static const String BASIC_COLOR_BLUE = 'blue';
static const String HEX_BLACK = '#000000';
static const String HEX_WHITE = '#FFFFFF';
///
/// Converts the given [hex] color string to the corresponding int.
///
/// Note that when no alpha/opacity is specified, 0xFF is assumed.
///
static int hexToInt(String hex) {
final hexDigits = hex.startsWith('#') ? hex.substring(1) : hex;
final hexMask = hexDigits.length <= 6 ? 0xFF000000 : 0;
final hexValue = int.parse(hexDigits, radix: 16);
assert(hexValue >= 0 && hexValue <= 0xFFFFFFFF);
return hexValue | hexMask;