CarouselView.weighted constructor

const CarouselView.weighted({
  1. Key? key,
  2. EdgeInsets? padding,
  3. Color? backgroundColor,
  4. double? elevation,
  5. ShapeBorder? shape,
  6. WidgetStateProperty<Color?>? overlayColor,
  7. bool itemSnapping = false,
  8. double shrinkExtent = 0.0,
  9. CarouselController? controller,
  10. Axis scrollDirection = Axis.horizontal,
  11. bool reverse = false,
  12. bool allowFullyExpand = true,
  13. ScrollPhysics? physics,
  14. required List<int>? layoutWeights,
  15. 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;