createAccentSwatch static method

MaterialAccentColor createAccentSwatch(
  1. Color color
)

Create an Accent color swatch from a given single color value.

The provided color is used as the Accent swatch default color 200 in the returned swatch with lighter hues for lower index and darker shades for higher indexes.

Implementation

static MaterialAccentColor createAccentSwatch(Color color) {
  final Map<int, Color> swatch = <int, Color>{};
  final int a = color.alpha;
  final int r = color.red;
  final int g = color.green;
  final int b = color.blue;
  for (final int strength in _indexAccent) {
    final double ds = 0.2 - strength / 1000;
    swatch[strength] = Color.fromARGB(
        a,
        r + ((ds < 0 ? r : (255 - r)) * ds).round(),
        g + ((ds < 0 ? g : (255 - g)) * ds).round(),
        b + ((ds < 0 ? b : (255 - b)) * ds).round());
  }
  // The above gives a starting point, this tunes it a bit better, still far
  // from the real algorithm.
  swatch[100] = swatch[100]!.lighten(14);
  swatch[700] = swatch[700]!.lighten(2);
  return MaterialAccentColor(color.value, swatch);
}