Home > Net >  flutter carousel slider start from specific position
flutter carousel slider start from specific position

Time:09-17

I want to start carousel slider from a specific index. My carousel slider widget takes a props object which has below properties:

class Props {
  List<String> strings;
  int index;

  Props({
    required this.index,
    required this.strings,
  });
}

And my carousel slider is as:

    return CarouselSlider(
      options: CarouselOptions(
        ...
      ),
      carouselController: controller,
      items: widget.props.strings.map(
        (item) {
          ..some widget
        },
      ).toList(),
    );

Everything is all good except I want to start the carousel from widget.props.index. So rather than starting from index 0 of List<String> I can start from index 2 or 3.

CodePudding user response:

You could set the initialPage field by setting the options.

CarouselSlider(
  // ...
  options: CarouselOptions(
    initialPage: 2,
  ),
),
  • Related