change: replace own `Direction` to native `AxisDirection`
This commit is contained in:
parent
220952aa02
commit
1b99984773
|
|
@ -58,13 +58,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
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');
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -76,20 +76,20 @@ class _SwipeableCardsStackState extends State<SwipeableCardsStack>
|
|||
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<SwipeableCardsStack>
|
|||
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(() {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue