feat(swipe): add option to disable horizontal swipes
This commit is contained in:
parent
666959d21a
commit
037acfda1c
|
|
@ -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 &&
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue