INNER CODE UNIT · Dart

contrastColor

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

  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;
  }

  ///
  /// Fetches the basic color int values for red, green, blue from the given [hex] string.
  ///
  /// The values are returned inside a map with the following keys :
  /// * red
  /// * green
  /// * blue
  ///
  static Map<String, int> basicColorsFromHex(String hex) {
    hex = fillUpHex(hex);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…