createMaterialColor static method
Implementation
static MaterialColor createMaterialColor(Color color) {
List<double> strengths = <double>[.05, .1, .2, .3, .4, .5, .6, .7, .8, .9];
Map<int, Color> swatch = {};
final int r = color.red, g = color.green, b = color.blue;
for (var strength in strengths) {
final double ds = 0.5 - strength;
swatch[(strength * 1000).round()] = Color.fromRGBO(
r + ((ds < 0 ? r : (255 - r)) * ds).round(),
g + ((ds < 0 ? g : (255 - g)) * ds).round(),
b + ((ds < 0 ? b : (255 - b)) * ds).round(),
1,
);
}
return MaterialColor(color.value, swatch);
}