INNER CODE UNIT · Dart

isDark

Ephenodrom/Dart-Basic-Utils · lib/src/ColorUtils.dart:112

  static bool isDark(String hex) {
    var bC = basicColorsFromHex(hex);

    return calculateRelativeLuminance(
            bC[BASIC_COLOR_RED]!, bC[BASIC_COLOR_GREEN]!, bC[BASIC_COLOR_BLUE]!) <
        0.5;
  }

  ///
  /// Calculates the limunance for the given [hex] color and returns black as hex for bright colors, white as hex for dark colors.
  ///
  static String contrastColor(String hex) {
    var bC = basicColorsFromHex(hex);

    var luminance = calculateRelativeLuminance(
        bC[BASIC_COLOR_RED]!, bC[BASIC_COLOR_GREEN]!, bC[BASIC_COLOR_BLUE]!);
    return luminance > 0.5 ? HEX_BLACK : HEX_WHITE;
  }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…