Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/carousel_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class CarouselOptions {
/// Called whenever the carousel is scrolled
final ValueChanged<double?>? onScrolled;

/// Called whenever the carousel stops scrolling
final ValueChanged<int>? onEndScroll;

/// How the carousel should respond to user input.
///
/// For example, determines how the items continues to animate after the
Expand Down Expand Up @@ -148,6 +151,7 @@ class CarouselOptions {
this.enlargeCenterPage = false,
this.onPageChanged,
this.onScrolled,
this.onEndScroll,
this.scrollPhysics,
this.pageSnapping = true,
this.scrollDirection: Axis.horizontal,
Expand Down Expand Up @@ -178,6 +182,7 @@ class CarouselOptions {
bool? enlargeCenterPage,
Function(int index, CarouselPageChangedReason reason)? onPageChanged,
ValueChanged<double?>? onScrolled,
ValueChanged<int>? onEndScroll,
ScrollPhysics? scrollPhysics,
bool? pageSnapping,
Axis? scrollDirection,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions lib/carousel_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ class CarouselSliderState extends State<CarouselSlider>
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,
Expand Down Expand Up @@ -235,6 +242,13 @@ class CarouselSliderState extends State<CarouselSlider>
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,
Expand Down