diff --git a/lib/carousel_options.dart b/lib/carousel_options.dart index aef2664..a9d5208 100644 --- a/lib/carousel_options.dart +++ b/lib/carousel_options.dart @@ -77,6 +77,9 @@ class CarouselOptions { /// Called whenever the carousel is scrolled final ValueChanged? onScrolled; + /// Called whenever the carousel stops scrolling + final ValueChanged? onEndScroll; + /// How the carousel should respond to user input. /// /// For example, determines how the items continues to animate after the @@ -148,6 +151,7 @@ class CarouselOptions { this.enlargeCenterPage = false, this.onPageChanged, this.onScrolled, + this.onEndScroll, this.scrollPhysics, this.pageSnapping = true, this.scrollDirection: Axis.horizontal, @@ -178,6 +182,7 @@ class CarouselOptions { bool? enlargeCenterPage, Function(int index, CarouselPageChangedReason reason)? onPageChanged, ValueChanged? onScrolled, + ValueChanged? onEndScroll, ScrollPhysics? scrollPhysics, bool? pageSnapping, Axis? scrollDirection, @@ -205,6 +210,7 @@ class CarouselOptions { enlargeCenterPage: enlargeCenterPage ?? this.enlargeCenterPage, onPageChanged: onPageChanged ?? this.onPageChanged, onScrolled: onScrolled ?? this.onScrolled, + onEndScroll: onEndScroll ?? this.onEndScroll, scrollPhysics: scrollPhysics ?? this.scrollPhysics, pageSnapping: pageSnapping ?? this.pageSnapping, scrollDirection: scrollDirection ?? this.scrollDirection, diff --git a/lib/carousel_slider.dart b/lib/carousel_slider.dart index c9539df..be06b6f 100644 --- a/lib/carousel_slider.dart +++ b/lib/carousel_slider.dart @@ -202,6 +202,13 @@ class CarouselSliderState extends State notification is ScrollUpdateNotification) { widget.options.onScrolled!(carouselState!.pageController!.page); } + if (notification is ScrollEndNotification) { + widget.options.onEndScroll + ?.call(getRealIndex( + carouselState!.pageController!.page!.toInt(), + carouselState!.realPage - carouselState!.initialPage, + carouselState!.itemCount)); + } return false; }, child: wrapper, @@ -235,6 +242,13 @@ class CarouselSliderState extends State notification is ScrollUpdateNotification) { widget.options.onScrolled!(carouselState!.pageController!.page); } + if (notification is ScrollEndNotification) { + widget.options.onEndScroll + ?.call(getRealIndex( + carouselState!.pageController!.page!.toInt(), + carouselState!.realPage - carouselState!.initialPage, + carouselState!.itemCount)); + } return false; }, child: wrapper,