diff --git a/.gitignore b/.gitignore index ec50b22..94c8d7d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ .buildlog/ .history .svn/ +.serena/ # IntelliJ related *.iml diff --git a/lib/carousel_options.dart b/lib/carousel_options.dart index e19b85c..9e05143 100644 --- a/lib/carousel_options.dart +++ b/lib/carousel_options.dart @@ -98,6 +98,12 @@ class CarouselOptions { /// Default to `true`. final bool pauseAutoPlayOnTouch; + /// If `true`, the auto play function will be stopped (not paused) when user is interacting with + /// the carousel, and will NOT be resumed when user finishes interacting. + /// This option takes precedence over `pauseAutoPlayOnTouch`. + /// Default to `false`. + final bool stopAutoPlayOnTouch; + /// If `true`, the auto play function will be paused when user is calling /// pageController's `nextPage` or `previousPage` or `animateToPage` method. /// And after the animation complete, the auto play will be resumed. @@ -160,6 +166,7 @@ class CarouselOptions { this.disableCenter = false, this.padEnds = true, this.clipBehavior = Clip.hardEdge, + this.stopAutoPlayOnTouch = false, }); ///Generate new [CarouselOptions] based on old ones. @@ -189,7 +196,8 @@ class CarouselOptions { double? enlargeFactor, bool? disableCenter, Clip? clipBehavior, - bool? padEnds}) => + bool? padEnds, + bool? stopAutoPlayOnTouch}) => CarouselOptions( height: height ?? this.height, aspectRatio: aspectRatio ?? this.aspectRatio, @@ -219,5 +227,6 @@ class CarouselOptions { disableCenter: disableCenter ?? this.disableCenter, clipBehavior: clipBehavior ?? this.clipBehavior, padEnds: padEnds ?? this.padEnds, + stopAutoPlayOnTouch: stopAutoPlayOnTouch ?? this.stopAutoPlayOnTouch, ); } diff --git a/lib/carousel_slider.dart b/lib/carousel_slider.dart index 44ea6c7..18dba20 100644 --- a/lib/carousel_slider.dart +++ b/lib/carousel_slider.dart @@ -279,7 +279,10 @@ class CarouselSliderState extends State } void onPanDown() { - if (widget.options.pauseAutoPlayOnTouch) { + // stopAutoPlayOnTouch takes precedence over pauseAutoPlayOnTouch + if (widget.options.stopAutoPlayOnTouch) { + clearTimer(); + } else if (widget.options.pauseAutoPlayOnTouch) { clearTimer(); } @@ -287,7 +290,9 @@ class CarouselSliderState extends State } void onPanUp() { - if (widget.options.pauseAutoPlayOnTouch) { + // Only resume if stopAutoPlayOnTouch is false + // If stopAutoPlayOnTouch is true, the timer stays stopped + if (!widget.options.stopAutoPlayOnTouch && widget.options.pauseAutoPlayOnTouch) { resumeTimer(); } }