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++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir == Direction.left) {
|
if (dir == AxisDirection.left) {
|
||||||
debugPrint('onDisliked ${(widget as CardView).text} $index');
|
debugPrint('onDisliked ${(widget as CardView).text} $index');
|
||||||
} else if (dir == Direction.right) {
|
} else if (dir == AxisDirection.right) {
|
||||||
debugPrint('onLiked ${(widget as CardView).text} $index');
|
debugPrint('onLiked ${(widget as CardView).text} $index');
|
||||||
} else if (dir == Direction.up) {
|
} else if (dir == AxisDirection.up) {
|
||||||
debugPrint('onUp ${(widget as CardView).text} $index');
|
debugPrint('onUp ${(widget as CardView).text} $index');
|
||||||
} else if (dir == Direction.down) {
|
} else if (dir == AxisDirection.down) {
|
||||||
debugPrint('onDown ${(widget as CardView).text} $index');
|
debugPrint('onDown ${(widget as CardView).text} $index');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -76,20 +76,20 @@ class _SwipeableCardsStackState extends State<SwipeableCardsStack>
|
||||||
Alignment frontCardAlign = cardsAlign[2];
|
Alignment frontCardAlign = cardsAlign[2];
|
||||||
double frontCardRot = 0.0;
|
double frontCardRot = 0.0;
|
||||||
|
|
||||||
void _triggerSwipe(Direction dir) {
|
void _triggerSwipe(AxisDirection dir) {
|
||||||
final swipedCallback = widget.onCardSwiped ?? (_, __, ___) => true;
|
final swipedCallback = widget.onCardSwiped ?? (_, __, ___) => true;
|
||||||
bool? shouldAnimate = false;
|
bool? shouldAnimate = false;
|
||||||
if (dir == Direction.left) {
|
if (dir == AxisDirection.left) {
|
||||||
shouldAnimate = swipedCallback(Direction.left, index, cards[0]);
|
shouldAnimate = swipedCallback(AxisDirection.left, index, cards[0]);
|
||||||
frontCardAlign = const Alignment(-0.001, 0.0);
|
frontCardAlign = const Alignment(-0.001, 0.0);
|
||||||
} else if (dir == Direction.right) {
|
} else if (dir == AxisDirection.right) {
|
||||||
shouldAnimate = swipedCallback(Direction.right, index, cards[0]);
|
shouldAnimate = swipedCallback(AxisDirection.right, index, cards[0]);
|
||||||
frontCardAlign = const Alignment(0.001, 0.0);
|
frontCardAlign = const Alignment(0.001, 0.0);
|
||||||
} else if (dir == Direction.up) {
|
} else if (dir == AxisDirection.up) {
|
||||||
shouldAnimate = swipedCallback(Direction.up, index, cards[0]);
|
shouldAnimate = swipedCallback(AxisDirection.up, index, cards[0]);
|
||||||
frontCardAlign = const Alignment(0.0, -0.001);
|
frontCardAlign = const Alignment(0.0, -0.001);
|
||||||
} else if (dir == Direction.down) {
|
} else if (dir == AxisDirection.down) {
|
||||||
shouldAnimate = swipedCallback(Direction.down, index, cards[0]);
|
shouldAnimate = swipedCallback(AxisDirection.down, index, cards[0]);
|
||||||
frontCardAlign = const Alignment(0.0, 0.001);
|
frontCardAlign = const Alignment(0.0, 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,18 +183,18 @@ class _SwipeableCardsStackState extends State<SwipeableCardsStack>
|
||||||
bool? shouldAnimate = false;
|
bool? shouldAnimate = false;
|
||||||
if (frontCardAlign.x > 3.0) {
|
if (frontCardAlign.x > 3.0) {
|
||||||
shouldAnimate =
|
shouldAnimate =
|
||||||
onCardSwiped(Direction.right, index, cards[0]);
|
onCardSwiped(AxisDirection.right, index, cards[0]);
|
||||||
} else if (frontCardAlign.x < -3.0) {
|
} else if (frontCardAlign.x < -3.0) {
|
||||||
shouldAnimate =
|
shouldAnimate =
|
||||||
onCardSwiped(Direction.left, index, cards[0]);
|
onCardSwiped(AxisDirection.left, index, cards[0]);
|
||||||
} else if (frontCardAlign.y < -3.0 &&
|
} else if (frontCardAlign.y < -3.0 &&
|
||||||
widget.enableSwipeUp) {
|
widget.enableSwipeUp) {
|
||||||
shouldAnimate =
|
shouldAnimate =
|
||||||
onCardSwiped(Direction.up, index, cards[0]);
|
onCardSwiped(AxisDirection.up, index, cards[0]);
|
||||||
} else if (frontCardAlign.y > 3.0 &&
|
} else if (frontCardAlign.y > 3.0 &&
|
||||||
widget.enableSwipeDown) {
|
widget.enableSwipeDown) {
|
||||||
shouldAnimate =
|
shouldAnimate =
|
||||||
onCardSwiped(Direction.down, index, cards[0]);
|
onCardSwiped(AxisDirection.down, index, cards[0]);
|
||||||
} else {
|
} else {
|
||||||
// Return to the initial rotation and alignment
|
// Return to the initial rotation and alignment
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
typedef TriggerListener = void Function(Direction dir);
|
typedef TriggerListener = void Function(AxisDirection dir);
|
||||||
typedef AppendItem = void Function(Widget item);
|
typedef AppendItem = void Function(Widget item);
|
||||||
typedef EnableSwipe = void Function(bool dir);
|
typedef EnableSwipe = void Function(bool dir);
|
||||||
|
|
||||||
|
|
@ -10,19 +10,19 @@ class SwipeableCardsStackController {
|
||||||
late EnableSwipe enableSwipeListener;
|
late EnableSwipe enableSwipeListener;
|
||||||
|
|
||||||
void triggerSwipeLeft() {
|
void triggerSwipeLeft() {
|
||||||
return listener.call(Direction.left);
|
return listener.call(AxisDirection.left);
|
||||||
}
|
}
|
||||||
|
|
||||||
void triggerSwipeRight() {
|
void triggerSwipeRight() {
|
||||||
return listener.call(Direction.right);
|
return listener.call(AxisDirection.right);
|
||||||
}
|
}
|
||||||
|
|
||||||
void triggerSwipeUp() {
|
void triggerSwipeUp() {
|
||||||
return listener.call(Direction.up);
|
return listener.call(AxisDirection.up);
|
||||||
}
|
}
|
||||||
|
|
||||||
void triggerSwipeDown() {
|
void triggerSwipeDown() {
|
||||||
return listener.call(Direction.down);
|
return listener.call(AxisDirection.down);
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendItem(Widget item) {
|
void appendItem(Widget item) {
|
||||||
|
|
@ -33,10 +33,3 @@ class SwipeableCardsStackController {
|
||||||
return enableSwipeListener.call(isSwipeEnabled);
|
return enableSwipeListener.call(isSwipeEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Direction {
|
|
||||||
left,
|
|
||||||
right,
|
|
||||||
up,
|
|
||||||
down,
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue