CarouselView.builder constructor
const
CarouselView.builder({
- Key? key,
- EdgeInsets? padding,
- Color? backgroundColor,
- double? elevation,
- ShapeBorder? shape,
- Clip? itemClipBehavior,
- WidgetStateProperty<
Color?> ? overlayColor, - bool itemSnapping = false,
- double shrinkExtent = 0.0,
- CarouselController? controller,
- Axis scrollDirection = Axis.horizontal,
- bool reverse = false,
- ValueChanged<
int> ? onTap, - bool enableSplash = true,
- required double itemExtent,
- required NullableIndexedWidgetBuilder? itemBuilder,
- int? itemCount,
- ValueChanged<
int> ? onIndexChanged, - bool infinite = false,
- ScrollPhysics? physics,
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.
{@tool dartpad} This example shows how to create a carousel with 1000 items using lazy loading:
** See code in examples/api/lib/material/carousel/carousel.1.dart ** {@end-tool}
See also:
- CarouselView.new, which creates a carousel with explicit children.
- CarouselView.weighted, which creates a carousel with weighted items.
- CarouselView.weightedBuilder, which creates a carousel with weighted items using lazy loading.
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,
this.onIndexChanged,
this.infinite = false,
this.physics,
}) : consumeMaxWeight = true,
flexWeights = null,
children = const <Widget>[];