diff --git a/example/lib/main.dart b/example/lib/main.dart index c4d162d..95f1a89 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -58,13 +58,13 @@ class _MyHomePageState extends State { counter++; } - if (dir == Direction.left) { + if (dir == AxisDirection.left) { debugPrint('onDisliked ${(widget as CardView).text} $index'); - } else if (dir == Direction.right) { + } else if (dir == AxisDirection.right) { debugPrint('onLiked ${(widget as CardView).text} $index'); - } else if (dir == Direction.up) { + } else if (dir == AxisDirection.up) { debugPrint('onUp ${(widget as CardView).text} $index'); - } else if (dir == Direction.down) { + } else if (dir == AxisDirection.down) { debugPrint('onDown ${(widget as CardView).text} $index'); } }, diff --git a/lib/src/swipeable_cards_stack.dart b/lib/src/swipeable_cards_stack.dart index ee38cb1..7e4de80 100644 --- a/lib/src/swipeable_cards_stack.dart +++ b/lib/src/swipeable_cards_stack.dart @@ -76,20 +76,20 @@ class _SwipeableCardsStackState extends State Alignment frontCardAlign = cardsAlign[2]; double frontCardRot = 0.0; - void _triggerSwipe(Direction dir) { + void _triggerSwipe(AxisDirection dir) { final swipedCallback = widget.onCardSwiped ?? (_, __, ___) => true; bool? shouldAnimate = false; - if (dir == Direction.left) { - shouldAnimate = swipedCallback(Direction.left, index, cards[0]); + if (dir == AxisDirection.left) { + shouldAnimate = swipedCallback(AxisDirection.left, index, cards[0]); frontCardAlign = const Alignment(-0.001, 0.0); - } else if (dir == Direction.right) { - shouldAnimate = swipedCallback(Direction.right, index, cards[0]); + } else if (dir == AxisDirection.right) { + shouldAnimate = swipedCallback(AxisDirection.right, index, cards[0]); frontCardAlign = const Alignment(0.001, 0.0); - } else if (dir == Direction.up) { - shouldAnimate = swipedCallback(Direction.up, index, cards[0]); + } else if (dir == AxisDirection.up) { + shouldAnimate = swipedCallback(AxisDirection.up, index, cards[0]); frontCardAlign = const Alignment(0.0, -0.001); - } else if (dir == Direction.down) { - shouldAnimate = swipedCallback(Direction.down, index, cards[0]); + } else if (dir == AxisDirection.down) { + shouldAnimate = swipedCallback(AxisDirection.down, index, cards[0]); frontCardAlign = const Alignment(0.0, 0.001); } @@ -183,18 +183,18 @@ class _SwipeableCardsStackState extends State bool? shouldAnimate = false; if (frontCardAlign.x > 3.0) { shouldAnimate = - onCardSwiped(Direction.right, index, cards[0]); + onCardSwiped(AxisDirection.right, index, cards[0]); } else if (frontCardAlign.x < -3.0) { shouldAnimate = - onCardSwiped(Direction.left, index, cards[0]); + onCardSwiped(AxisDirection.left, index, cards[0]); } else if (frontCardAlign.y < -3.0 && widget.enableSwipeUp) { shouldAnimate = - onCardSwiped(Direction.up, index, cards[0]); + onCardSwiped(AxisDirection.up, index, cards[0]); } else if (frontCardAlign.y > 3.0 && widget.enableSwipeDown) { shouldAnimate = - onCardSwiped(Direction.down, index, cards[0]); + onCardSwiped(AxisDirection.down, index, cards[0]); } else { // Return to the initial rotation and alignment setState(() { diff --git a/lib/src/swipeable_cards_stack_controller.dart b/lib/src/swipeable_cards_stack_controller.dart index 8d27f50..93fc0ed 100644 --- a/lib/src/swipeable_cards_stack_controller.dart +++ b/lib/src/swipeable_cards_stack_controller.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -typedef TriggerListener = void Function(Direction dir); +typedef TriggerListener = void Function(AxisDirection dir); typedef AppendItem = void Function(Widget item); typedef EnableSwipe = void Function(bool dir); @@ -10,19 +10,19 @@ class SwipeableCardsStackController { late EnableSwipe enableSwipeListener; void triggerSwipeLeft() { - return listener.call(Direction.left); + return listener.call(AxisDirection.left); } void triggerSwipeRight() { - return listener.call(Direction.right); + return listener.call(AxisDirection.right); } void triggerSwipeUp() { - return listener.call(Direction.up); + return listener.call(AxisDirection.up); } void triggerSwipeDown() { - return listener.call(Direction.down); + return listener.call(AxisDirection.down); } void appendItem(Widget item) { @@ -33,10 +33,3 @@ class SwipeableCardsStackController { return enableSwipeListener.call(isSwipeEnabled); } } - -enum Direction { - left, - right, - up, - down, -}