CarouselView.builder constructor
- 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,
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:
- 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,
}) : consumeMaxWeight = true,
flexWeights = null,
children = const <Widget>[];