CarouselView.builder constructor

const CarouselView.builder({
  1. Key? key,
  2. EdgeInsets? padding,
  3. Color? backgroundColor,
  4. double? elevation,
  5. ShapeBorder? shape,
  6. Clip? itemClipBehavior,
  7. WidgetStateProperty<Color?>? overlayColor,
  8. bool itemSnapping = false,
  9. double shrinkExtent = 0.0,
  10. CarouselController? controller,
  11. Axis scrollDirection = Axis.horizontal,
  12. bool reverse = false,
  13. ValueChanged<int>? onTap,
  14. bool enableSplash = true,
  15. required double itemExtent,
  16. required NullableIndexedWidgetBuilder? itemBuilder,
  17. int? itemCount,
})

Creates a scrollable carousel with fixed-sized items created on demand.

This constructor allows lazy loading of carousel items. Only items that are visible (or about to be visible) are built, improving performance when dealing with large numbers of items.

The itemBuilder callback will be called only with indices greater than or equal to zero and less than itemCount.

This example shows how to create a carousel with 1000 items using lazy loading:
link

To create a local project with this code sample, run:
flutter create --sample=material.CarouselView.CarouselView.builder.1 mysample

See also:

Implementation

const CarouselView.builder({
  super.key,
  this.padding,
  this.backgroundColor,
  this.elevation,
  this.shape,
  this.itemClipBehavior,
  this.overlayColor,
  this.itemSnapping = false,
  this.shrinkExtent = 0.0,
  this.controller,
  this.scrollDirection = Axis.horizontal,
  this.reverse = false,
  this.onTap,
  this.enableSplash = true,
  required double this.itemExtent,
  required this.itemBuilder,
  this.itemCount,
}) : consumeMaxWeight = true,
     flexWeights = null,
     children = const <Widget>[];