customSwatch static method

ColorSwatch<Object> customSwatch(
  1. Color color,
  2. Map<ColorSwatch<Object>, String>? customSwatch
)

Returns the custom color swatch for the color given to it.

If the color is a part of a custom color swatch, then the custom color swatch will be returned. If the color is not in these swatches, it will create a primary material swatch for the given color using the given color as the mid 500 value and return this created custom primary color Swatch. This color swatch can then be used as a primary Material color swatch.

Implementation

static ColorSwatch<Object> customSwatch(
    Color color, Map<ColorSwatch<Object>, String>? customSwatch) {
  if (customSwatch != null) {
    for (final ColorSwatch<Object> swatch in customSwatch.keys) {
      for (final int i in _indexPrimary) {
        if (swatch[i] == color || swatch[i]?.value == color.value) {
          return swatch; // Color found in a swatch so we return it
        }
      }
    }
  }
  // Did not find the given color in the custom color swatch,
  // so make a custom material swatch based on the given color and return it.
  return createPrimarySwatch(color);
}