nextColor method

Color nextColor (
  1. {int red,
  2. int green,
  3. int blue,
  4. int alpha,
  5. double opacity}
)

Generates a random Color with uniformly distributed red, green & blue values.

You can optionally specify some components of the generated Color:

  • red, green or blue
  • either alpha or opacity

Implementation

Color nextColor({
  int red,
  int green,
  int blue,
  int alpha,
  double opacity,
}) {
  assert(
    alpha == null || opacity == null,
    'You cannot specify both alpha and opacity.',
  );

  final r = red ?? nextInt(_channelMax);
  final g = green ?? nextInt(_channelMax);
  final b = blue ?? nextInt(_channelMax);

  if (opacity != null) {
    return Color.fromRGBO(r, g, b, opacity);
  }
  return Color.fromARGB(alpha ?? nextInt(_channelMax), r, g, b);
}