From 3fbcd8af69fc5748bef4b8ecad9b98e3831fe087 Mon Sep 17 00:00:00 2001 From: gralmeidan Date: Thu, 7 Dec 2023 13:14:11 -0400 Subject: [PATCH] fix: clearing timer before user stops interacting with carousel --- lib/carousel_slider.dart | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/lib/carousel_slider.dart b/lib/carousel_slider.dart index c9539df..5ae9ee4 100644 --- a/lib/carousel_slider.dart +++ b/lib/carousel_slider.dart @@ -208,26 +208,16 @@ class CarouselSliderState extends State ); } - return RawGestureDetector( + return Listener( behavior: HitTestBehavior.opaque, - gestures: { - _MultipleGestureRecognizer: - GestureRecognizerFactoryWithHandlers<_MultipleGestureRecognizer>( - () => _MultipleGestureRecognizer(), - (_MultipleGestureRecognizer instance) { - instance.onStart = (_) { - onStart(); - }; - instance.onDown = (_) { - onPanDown(); - }; - instance.onEnd = (_) { - onPanUp(); - }; - instance.onCancel = () { - onPanUp(); - }; - }), + onPointerDown: (_) { + onPanDown(); + }, + onPointerCancel: (_) { + onPanUp(); + }, + onPointerUp: (_) { + onPanUp(); }, child: NotificationListener( onNotification: (Notification notification) { @@ -274,10 +264,6 @@ class CarouselSliderState extends State child: Container(child: child, width: width, height: height)); } - void onStart() { - changeMode(CarouselPageChangedReason.manual); - } - void onPanDown() { if (widget.options.pauseAutoPlayOnTouch) { clearTimer(); @@ -355,7 +341,7 @@ class CarouselSliderState extends State BuildContext storageContext = carouselState! .pageController!.position.context.storageContext; final double? previousSavedPosition = - PageStorage.of(storageContext)?.readState(storageContext) + PageStorage.of(storageContext).readState(storageContext) as double?; if (previousSavedPosition != null) { itemOffset = previousSavedPosition - idx.toDouble(); @@ -394,5 +380,3 @@ class CarouselSliderState extends State )); } } - -class _MultipleGestureRecognizer extends PanGestureRecognizer {}