InfiniteCarousel.builder constructor

InfiniteCarousel.builder(
  1. {Key? key,
  2. required int itemCount,
  3. required double itemExtent,
  4. required Widget itemBuilder(
    1. BuildContext context,
    2. int itemIndex,
    3. int realIndex
    ),
  5. ScrollPhysics? physics,
  6. ScrollController? controller,
  7. void onIndexChanged(
    1. int
    )?,
  8. double anchor = 0.0,
  9. bool loop = true,
  10. double velocityFactor = 0.2,
  11. Axis axisDirection = Axis.horizontal,
  12. bool center = true,
  13. ScrollBehavior? scrollBehavior}
)

Infinite Carousel

Based on ListWheelScrollView to create smooth scroll effect and physics.

Implementation

InfiniteCarousel.builder({
  super.key,
  required this.itemCount,
  required this.itemExtent,
  required this.itemBuilder,
  this.physics,
  this.controller,
  this.onIndexChanged,
  this.anchor = 0.0,
  this.loop = true,
  this.velocityFactor = 0.2,
  this.axisDirection = Axis.horizontal,
  this.center = true,
  this.scrollBehavior,
})  : assert(itemExtent > 0),
      assert(itemCount > 0),
      assert(velocityFactor > 0.0 && velocityFactor <= 1.0),
      childDelegate = SliverChildBuilderDelegate(
        (context, index) =>
            itemBuilder(context, index.abs() % itemCount, index),
        childCount: loop ? null : itemCount,
      ),
      reversedChildDelegate = loop
          ? SliverChildBuilderDelegate(
              (context, index) => itemBuilder(context,
                  itemCount - (index.abs() % itemCount) - 1, -(index + 1)),
            )
          : null;