The CustomCarousel widget displays a list of children with fully customizable scrolling animations. It manages a visible subset of children based on itemCountBefore and itemCountAfter and uses an effectsBuilder to apply animations to each child based on its scrollRatio relative to the selected item.
Key features:
- Custom Animations: Use the
effectsBuilder to wrap children in animations (e.g., scaling, opacity, or rotation) driven by the scroll position. - Scroll Control: Use a
CustomCarouselScrollController to programmatically navigate to specific items. - Looping: Enable
loop: true for infinite scrolling in both directions. - Tap to Select: When
tapToSelect is true, tapping an unselected item will animate the carousel to that item. - Depth Control: Use
depthOrder to control which items appear in front of others (e.g., selectedInFront keeps the active item on top).
CustomCarousel(
effectsBuilder: (index, scrollRatio, child) {
// Apply custom animations based on scrollRatio
return Transform.scale(
scale: 1.0 - (scrollRatio.abs() * 0.2),
child: child,
);
},
children: [
Container(color: Colors.red, width: 100, height: 100),
Container(color: Colors.blue, width: 100, height: 100),
Container(color: Colors.green, width: 100, height: 100),
],
)