feat(swipe): add option to disable horizontal swipes

This commit is contained in:
Ricardo Dalarme 2023-01-13 12:24:37 -03:00
parent 666959d21a
commit 037acfda1c
1 changed files with 7 additions and 2 deletions

View File

@ -27,6 +27,8 @@ class SwipeableCardsStack extends StatefulWidget {
final Function? appendItemCallback; final Function? appendItemCallback;
final bool enableSwipeUp; final bool enableSwipeUp;
final bool enableSwipeDown; final bool enableSwipeDown;
final bool enableSwipeLeft;
final bool enableSwipeRight;
SwipeableCardsStack({ SwipeableCardsStack({
Key? key, Key? key,
@ -43,6 +45,8 @@ class SwipeableCardsStack extends StatefulWidget {
this.appendItemCallback, this.appendItemCallback,
this.enableSwipeUp = true, this.enableSwipeUp = true,
this.enableSwipeDown = true, this.enableSwipeDown = true,
this.enableSwipeLeft = true,
this.enableSwipeRight = true,
}) : super(key: key) { }) : super(key: key) {
cardsSize[0] = Size( cardsSize[0] = Size(
MediaQuery.of(context).size.width * cardWidthTopMul, MediaQuery.of(context).size.width * cardWidthTopMul,
@ -181,10 +185,11 @@ class _SwipeableCardsStackState extends State<SwipeableCardsStack>
final onCardSwiped = final onCardSwiped =
widget.onCardSwiped ?? (_, __, ___) => true; widget.onCardSwiped ?? (_, __, ___) => true;
bool? shouldAnimate = false; bool? shouldAnimate = false;
if (frontCardAlign.x > 3.0) { if (frontCardAlign.x > 3.0 && widget.enableSwipeRight) {
shouldAnimate = shouldAnimate =
onCardSwiped(AxisDirection.right, index, cards[0]); onCardSwiped(AxisDirection.right, index, cards[0]);
} else if (frontCardAlign.x < -3.0) { } else if (frontCardAlign.x < -3.0 &&
widget.enableSwipeLeft) {
shouldAnimate = shouldAnimate =
onCardSwiped(AxisDirection.left, index, cards[0]); onCardSwiped(AxisDirection.left, index, cards[0]);
} else if (frontCardAlign.y < -3.0 && } else if (frontCardAlign.y < -3.0 &&