CarouselView.weightedBuilder 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,
- bool consumeMaxWeight = true,
- ValueChanged<
int> ? onTap, - bool enableSplash = true,
- required List<
int> flexWeights, - required NullableIndexedWidgetBuilder? itemBuilder,
- int? itemCount,
Creates a scrollable carousel with weighted items created on demand.
This constructor combines the benefits of CarouselView.weighted with lazy loading. Items are built on demand while maintaining the weighted layout system.
The flexWeights parameter determines the layout, and itemBuilder
creates items as they become visible.
This example shows how to create a weighted carousel with lazy loading:
link
CarouselView.weightedBuilder(
flexWeights: const <int>[1, 7, 1],
itemCount: 100,
itemBuilder: (BuildContext context, int index) {
return ColoredBox(
color: Colors.primaries[index % Colors.primaries.length],
child: Center(
child: Text('Item $index'),
),
);
},
)
See also:
- CarouselView.new, which creates a carousel with explicit children.
- CarouselView.weighted, which creates a carousel with weighted items.
- CarouselView.builder, which creates a carousel with fixed-sized items using lazy loading.
Implementation
const CarouselView.weightedBuilder({
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.consumeMaxWeight = true,
this.onTap,
this.enableSplash = true,
required List<int> this.flexWeights,
required this.itemBuilder,
this.itemCount,
}) : itemExtent = null,
children = const <Widget>[];