From 037acfda1c25011fc942b0e4b26b59d27c082d00 Mon Sep 17 00:00:00 2001 From: Ricardo Dalarme Date: Fri, 13 Jan 2023 12:24:37 -0300 Subject: [PATCH] feat(swipe): add option to disable horizontal swipes --- lib/src/swipeable_cards_stack.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/swipeable_cards_stack.dart b/lib/src/swipeable_cards_stack.dart index 7e4de80..0d487ac 100644 --- a/lib/src/swipeable_cards_stack.dart +++ b/lib/src/swipeable_cards_stack.dart @@ -27,6 +27,8 @@ class SwipeableCardsStack extends StatefulWidget { final Function? appendItemCallback; final bool enableSwipeUp; final bool enableSwipeDown; + final bool enableSwipeLeft; + final bool enableSwipeRight; SwipeableCardsStack({ Key? key, @@ -43,6 +45,8 @@ class SwipeableCardsStack extends StatefulWidget { this.appendItemCallback, this.enableSwipeUp = true, this.enableSwipeDown = true, + this.enableSwipeLeft = true, + this.enableSwipeRight = true, }) : super(key: key) { cardsSize[0] = Size( MediaQuery.of(context).size.width * cardWidthTopMul, @@ -181,10 +185,11 @@ class _SwipeableCardsStackState extends State final onCardSwiped = widget.onCardSwiped ?? (_, __, ___) => true; bool? shouldAnimate = false; - if (frontCardAlign.x > 3.0) { + if (frontCardAlign.x > 3.0 && widget.enableSwipeRight) { shouldAnimate = onCardSwiped(AxisDirection.right, index, cards[0]); - } else if (frontCardAlign.x < -3.0) { + } else if (frontCardAlign.x < -3.0 && + widget.enableSwipeLeft) { shouldAnimate = onCardSwiped(AxisDirection.left, index, cards[0]); } else if (frontCardAlign.y < -3.0 &&