serenader2014 / flutter_carousel_slider

A flutter carousel widget, support infinite scroll, and custom child widget.
https://pub.dev/packages/carousel_slider
MIT License
1.55k stars 517 forks source link

how to get listener when carousel got slided manual by user #399

Closed FDhunterz closed 1 year ago

FDhunterz commented 1 year ago

anyone can help me?

MatheusFelix1796 commented 1 year ago

If I understood correctly, you are trying to identify whenever the carousel's pages are changed by manually scrolling between them.

You can do the following:

On your CarouselOptions, the onPageChanged property should include a verification for reason == CarouselPageChangedReason.manual:

We have 3 ways of changing the page on the carousel, which are the CarouselPageChangedReason enum: controller, timed and manual. By calling the controller.[next or previous]Page() - controller, By having passed the autoPlayInterval time set for it changing automatically - timed By the user manually scrolling from one page to another - manual.

onPageChanged: (index, reason) {
    if (reason == CarouselPageChangedReason.manual) {
      //do what you want here
    }
},