Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue where the autoplay will be triggered while the user is interacting with it. #431

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 10 additions & 26 deletions lib/carousel_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,26 +208,16 @@ class CarouselSliderState extends State<CarouselSlider>
);
}

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) {
Expand Down Expand Up @@ -274,10 +264,6 @@ class CarouselSliderState extends State<CarouselSlider>
child: Container(child: child, width: width, height: height));
}

void onStart() {
changeMode(CarouselPageChangedReason.manual);
}

void onPanDown() {
if (widget.options.pauseAutoPlayOnTouch) {
clearTimer();
Expand Down Expand Up @@ -355,7 +341,7 @@ class CarouselSliderState extends State<CarouselSlider>
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();
Expand Down Expand Up @@ -394,5 +380,3 @@ class CarouselSliderState extends State<CarouselSlider>
));
}
}

class _MultipleGestureRecognizer extends PanGestureRecognizer {}