createAccentSwatch static method
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.alpha8bit;
final int r = color.red8bit;
final int g = color.green8bit;
final int b = color.blue8bit;
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.value32bit, swatch);
}