getMaterialColor method

MaterialColor? getMaterialColor(
  1. Color? color
)
inherited

No longer used

Implementation

// MaterialColor? _materialColor(Color? color) {
//   //
//   if (color == null) {
//     return null;
//   }
//   final strengths = <double>[.05];
//   final swatch = <int, Color>{};
//   final int r = color.red, g = color.green, b = color.blue;
//   for (int i = 1; i < 10; i++) {
//     strengths.add(double.parse((0.1 * i).toStringAsFixed(2)));
//   }
//   int cnt = 0;
//   for (final strength in strengths) {
//     final double ds = 0.5 - strength;
//     cnt = cnt + 1;
//     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(),
//       0.1 * cnt,
//     );
//   }
//   return MaterialColor(color.value, swatch);
// }

///
MaterialColor? getMaterialColor(Color? color) {
  //
  if (color == null) {
    return null;
  }

  final int red = color.red;
  final int green = color.green;
  final int blue = color.blue;

  final Map<int, Color> shades = {
    50: Color.fromRGBO(red, green, blue, .1),
    100: Color.fromRGBO(red, green, blue, .2),
    200: Color.fromRGBO(red, green, blue, .3),
    300: Color.fromRGBO(red, green, blue, .4),
    400: Color.fromRGBO(red, green, blue, .5),
    500: Color.fromRGBO(red, green, blue, .6),
    600: Color.fromRGBO(red, green, blue, .7),
    700: Color.fromRGBO(red, green, blue, .8),
    800: Color.fromRGBO(red, green, blue, .9),
    900: Color.fromRGBO(red, green, blue, 1),
  };
  return MaterialColor(color.value, shades);
}