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

Left and Right swipe allowed control added #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
35 changes: 28 additions & 7 deletions lib/draggable_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -229,13 +233,30 @@ class _DraggableCardState extends State<DraggableCard>
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(
Expand Down
8 changes: 8 additions & 0 deletions lib/swipe_cards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -169,6 +173,8 @@ class _SwipeCardsState extends State<SwipeCards> {
card: _buildBackCard(),
upSwipeAllowed: widget.upSwipeAllowed,
isBackCard: true,
leftSwipeAllowed: widget.leftSwipeAllowed,
rightSwipeAllowed: widget.rightSwipeAllowed,
),
if (widget.matchEngine.currentItem != null)
DraggableCard(
Expand All @@ -179,6 +185,8 @@ class _SwipeCardsState extends State<SwipeCards> {
onSlideOutComplete: _onSlideOutComplete,
upSwipeAllowed: widget.upSwipeAllowed,
isBackCard: false,
leftSwipeAllowed: widget.leftSwipeAllowed,
rightSwipeAllowed: widget.rightSwipeAllowed,
)
],
);
Expand Down