CarouselView.weighted constructor
const
CarouselView.weighted({
- Key? key,
- EdgeInsets? padding,
- Color? backgroundColor,
- double? elevation,
- ShapeBorder? shape,
- WidgetStateProperty<
Color?> ? overlayColor, - bool itemSnapping = false,
- double shrinkExtent = 0.0,
- CarouselController? controller,
- Axis scrollDirection = Axis.horizontal,
- bool reverse = false,
- bool allowFullyExpand = true,
- ScrollPhysics? physics,
- required List<
int> ? layoutWeights, - required List<
Widget> children,
Creates a scrollable list where the size of each child widget is dynamically
determined by the provided layoutWeights
.
The layoutWeights
parameter is required and defines the relative size
proportions of each child widget.
When allowFullyExpand
is set to true
, each child can be expanded to its
maximum size while scrolling. For example, with layoutWeights
of [1, 7, 1]
,
the initial weight of the first item is 1. However, by enabling
allowFullyExpand
and scrolling forward, the first item can expand to occupy
a weight of 7, leaving a weight of 1 as white space before it. This feature
is particularly useful for achieving "hero" and "center-aligned hero" layouts.
Implementation
const CarouselView.weighted({
super.key,
this.padding,
this.backgroundColor,
this.elevation,
this.shape,
this.overlayColor,
this.itemSnapping = false,
this.shrinkExtent = 0.0,
this.controller,
this.scrollDirection = Axis.horizontal,
this.reverse = false,
this.allowFullyExpand = true,
this.physics,
required this.layoutWeights,
required this.children,
}) : itemExtent = null;