imageUrl static method

String imageUrl({
  1. int width = 400,
  2. int height = 200,
  3. bool grayscale = false,
  4. int blur = 0,
})

Generate a random image URL with customizable options.

Parameters:

  • width: The width of the image.
  • height: The height of the image.
  • grayscale: Whether the image should be in grayscale.
  • blur: The level of blur (e.g., 5 for a moderate blur).

Implementation

static String imageUrl({
  int width = 400,
  int height = 200,
  bool grayscale = false,
  int blur = 0,
}) {
  final randomInt = _random.nextInt(1000);

  // Base URL
  String url = 'https://picsum.photos/$width/$height?random=$randomInt';

  // Add grayscale if needed
  if (grayscale) {
    url += '&grayscale';
  }

  // Add blur if needed
  if (blur > 0) {
    url += '&blur=$blur';
  }

  return url;
}