ImageScopeConfiguration constructor

ImageScopeConfiguration({
  1. required List<String> imageUrls,
  2. List<String>? descriptions,
  3. bool? showDescription,
})

Creates a image configuration with optional descriptions.

This constructor ensures that if descriptions are provided, their count must match the number of images in imageUrls. If showDescription is true, a mismatch will result in an ImageScopeError.

Parameters:

  • imageUrls: List of image URLs to be displayed.
  • descriptions: List of descriptions corresponding to the images (optional).
  • showDescription: Flag to toggle description visibility (optional).

Implementation

ImageScopeConfiguration({
  required this.imageUrls,
  this.descriptions,
  this.showDescription,
}) {
  // Check if descriptions are enabled and validate the length
  if (showDescription == true) {
    if (descriptions != null && descriptions!.length != imageUrls.length) {
      throw ImageScopeError(
        message:
            "Oops! The number of descriptions (${descriptions!.length}) doesn't match the number of images (${imageUrls.length}).",
        context: 'Description & Image Mismatch',
        solution:
            'Ensure that every image has a corresponding description, or leave descriptions null if not needed.',
      );
    }
  }
}