primarySwatch static method

MaterialColor primarySwatch(
  1. Color color
)

Returns a Material primary color swatch for the color given to it.

If the color is a part of a standard material primary color swatch, then the standard primary color swatch is returned.

If the color is not a Material standard primary color, create a material primary swatch for the given color using the given color as the mid 500 index value and return this created custom primary color swatch. This color swatch can then be used as a primary Material color swatch.

Implementation

static MaterialColor primarySwatch(Color color) {
  for (final ColorSwatch<Object> swatch in primaryColors) {
    for (final int i in _indexPrimaryWith850) {
      if (swatch[i] == color || swatch[i]?.value == color.value) {
        return swatch as MaterialColor; // Color found in a swatch, return it.
      }
    }
  }
  // Did not find the given color in a standard Material color swatch, make
  // a custom material primary swatch based on the given color and return it.
  return createPrimarySwatch(color);
}