color static method

CarouselTransitionBuilder color({
  1. List<Color> colors = const [],
  2. bool singleColor = true,
})

Implementation

static CarouselTransitionBuilder color({
  List<Color> colors = const [],
  bool singleColor = true,
}) {
  return (
    BuildContext context,
    Widget? child,
    int page,
    double currentPage,
    int index,
    double currentIndex,
    int itemCount,
  ) {

    if (colors.isEmpty) {
      return child ?? SizedBox();
    }

    final sequence = TweenSequence(colors
        .asMap()
        .entries
        .map((e) => TweenSequenceItem(
              weight: 1,
              tween: ColorTween(
                begin: e.value,
                end: colors[(e.key + 1) % colors.length],
              ),
            ))
        .toList());

    return DecoratedBox(
      decoration: BoxDecoration(
        color: sequence.evaluate(AlwaysStoppedAnimation((singleColor ? currentIndex : index) / itemCount)),
      ),
      child: child,
    );
  };
}