diff --git a/lib/draggable_card.dart b/lib/draggable_card.dart index 08d686a..44051d9 100644 --- a/lib/draggable_card.dart +++ b/lib/draggable_card.dart @@ -16,6 +16,8 @@ class DraggableCard extends StatefulWidget { final bool upSwipeAllowed; final EdgeInsets padding; final bool isBackCard; + final bool leftSwipeAllowed; + final bool rightSwipeAllowed; DraggableCard( {this.card, @@ -26,7 +28,9 @@ class DraggableCard extends StatefulWidget { this.onSlideRegionUpdate, this.upSwipeAllowed = true, this.isBackCard = false, - this.padding = EdgeInsets.zero}); + this.padding = EdgeInsets.zero, + this.leftSwipeAllowed = true, + this.rightSwipeAllowed = true}); @override _DraggableCardState createState() => _DraggableCardState(); @@ -229,13 +233,30 @@ class _DraggableCardState extends State final isInTopRegion = (cardOffset!.dy / context.size!.height) < -0.15; setState(() { - if (isInLeftRegion || isInRightRegion) { - slideOutTween = Tween( - begin: cardOffset, end: dragVector * (2 * context.size!.width)); - slideOutAnimation.forward(from: 0.0); + if (isInRightRegion) { + if (widget.rightSwipeAllowed) { + slideOutTween = Tween( + begin: cardOffset, end: dragVector * (2 * context.size!.width)); + slideOutAnimation.forward(from: 0.0); + + slideOutDirection = + isInLeftRegion ? SlideDirection.left : SlideDirection.right; + } else { + slideBackStart = cardOffset; + slideBackAnimation.forward(from: 0.0); + } + } else if (isInLeftRegion) { + if (widget.leftSwipeAllowed) { + slideOutTween = Tween( + begin: cardOffset, end: dragVector * (2 * context.size!.width)); + slideOutAnimation.forward(from: 0.0); - slideOutDirection = - isInLeftRegion ? SlideDirection.left : SlideDirection.right; + slideOutDirection = + isInLeftRegion ? SlideDirection.left : SlideDirection.right; + } else { + slideBackStart = cardOffset; + slideBackAnimation.forward(from: 0.0); + } } else if (isInTopRegion) { if (widget.upSwipeAllowed) { slideOutTween = Tween( diff --git a/lib/swipe_cards.dart b/lib/swipe_cards.dart index cf8e1ff..7e21a8f 100644 --- a/lib/swipe_cards.dart +++ b/lib/swipe_cards.dart @@ -12,6 +12,8 @@ class SwipeCards extends StatefulWidget { Function(SwipeItem, int)? itemChanged; final bool fillSpace; final bool upSwipeAllowed; + final bool leftSwipeAllowed; + final bool rightSwipeAllowed; SwipeCards({ Key? key, @@ -21,6 +23,8 @@ class SwipeCards extends StatefulWidget { this.fillSpace = true, this.upSwipeAllowed = false, this.itemChanged, + this.leftSwipeAllowed = true, + this.rightSwipeAllowed = true, }) : super(key: key); @override @@ -169,6 +173,8 @@ class _SwipeCardsState extends State { card: _buildBackCard(), upSwipeAllowed: widget.upSwipeAllowed, isBackCard: true, + leftSwipeAllowed: widget.leftSwipeAllowed, + rightSwipeAllowed: widget.rightSwipeAllowed, ), if (widget.matchEngine.currentItem != null) DraggableCard( @@ -179,6 +185,8 @@ class _SwipeCardsState extends State { onSlideOutComplete: _onSlideOutComplete, upSwipeAllowed: widget.upSwipeAllowed, isBackCard: false, + leftSwipeAllowed: widget.leftSwipeAllowed, + rightSwipeAllowed: widget.rightSwipeAllowed, ) ], );