shadeColor static method

Color shadeColor(
  1. Color color,
  2. int shade
)

Returns a shade color of the given color with the specified shade.

The shade argument is a number between 0 and 100 that determines the percentage of shade to apply to the color. A value of 0 indicates no shade, while a value of 100 indicates complete shade (i.e., black). Values in between produce varying shades of the original color.

For example, to get a color that is 30% lighter than Colors.red, you can use getShadeColor(Colors.red, 30), which returns a color that is similar to Colors.red.shade300, but slightly lighter.

Throws an AssertionError if the shade argument is not within the valid range of 0 to 100.

Implementation

static Color shadeColor(Color color, int shade) {
  assert(shade >= 0 && shade <= 100, 'The shade argument must be a number between 0 and 100.');
  final percent = shade / 100;
  final f = 1 - (percent * 0.5);
  return Color.fromRGBO(
    (color.red + ((255 - color.red) * f)).round(),
    (color.green + ((255 - color.green) * f)).round(),
    (color.blue + ((255 - color.blue) * f)).round(),
    1,
  );
}