generate static method

Color generate({
  1. int minOpacity = 150,
  2. int maxOpacity = 255,
})

Generates a random color with specified opacity range.

The minOpacity and maxOpacity parameters define the range for the alpha (opacity) value of the color. The alpha value will be randomly chosen between these two values (inclusive).

Example:

Color color = ColorGenerator.generate(minOpacity: 100, maxOpacity: 200);
print(color); // Output: Color(0xa5ff00ff) or similar
  • minOpacity: Minimum alpha value (0 to 255). Default is 150.
  • maxOpacity: Maximum alpha value (0 to 255). Default is 255.

Implementation

static Color generate({
  int minOpacity = 150,
  int maxOpacity = 255,
}) {
  int alpha = minOpacity + _random.nextInt(maxOpacity - minOpacity + 1);
  int red = _random.nextInt(256);
  int green = _random.nextInt(256);
  int blue = _random.nextInt(256);
  return Color.fromARGB(alpha, red, green, blue);
}