added possibility to enable swiping only on one axis (horizontal or vertical)
This commit is contained in:
parent
19a3f712a6
commit
4d261c9231
|
|
@ -42,6 +42,12 @@ class CardSwiper extends StatefulWidget {
|
||||||
/// direction in which the card gets swiped when triggered by controller, default set to right
|
/// direction in which the card gets swiped when triggered by controller, default set to right
|
||||||
final CardSwiperDirection direction;
|
final CardSwiperDirection direction;
|
||||||
|
|
||||||
|
/// set to false if you want your card to move only across the vertical axis when swiping
|
||||||
|
final bool isHorizontalSwipingEnabled;
|
||||||
|
|
||||||
|
/// set to false if you want your card to move only across the horizontal axis when swiping
|
||||||
|
final bool isVerticalSwipingEnabled;
|
||||||
|
|
||||||
const CardSwiper({
|
const CardSwiper({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.cards,
|
required this.cards,
|
||||||
|
|
@ -56,6 +62,8 @@ class CardSwiper extends StatefulWidget {
|
||||||
this.onSwipe,
|
this.onSwipe,
|
||||||
this.onEnd,
|
this.onEnd,
|
||||||
this.direction = CardSwiperDirection.right,
|
this.direction = CardSwiperDirection.right,
|
||||||
|
this.isHorizontalSwipingEnabled = true,
|
||||||
|
this.isVerticalSwipingEnabled = true,
|
||||||
}) : assert(
|
}) : assert(
|
||||||
maxAngle >= 0 && maxAngle <= 360,
|
maxAngle >= 0 && maxAngle <= 360,
|
||||||
'maxAngle must be between 0 and 360',
|
'maxAngle must be between 0 and 360',
|
||||||
|
|
@ -177,8 +185,12 @@ class _CardSwiperState extends State<CardSwiper>
|
||||||
onPanUpdate: (tapInfo) {
|
onPanUpdate: (tapInfo) {
|
||||||
if (!widget.isDisabled) {
|
if (!widget.isDisabled) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
if (widget.isHorizontalSwipingEnabled) {
|
||||||
_left += tapInfo.delta.dx;
|
_left += tapInfo.delta.dx;
|
||||||
|
}
|
||||||
|
if (widget.isVerticalSwipingEnabled) {
|
||||||
_top += tapInfo.delta.dy;
|
_top += tapInfo.delta.dy;
|
||||||
|
}
|
||||||
_total = _left + _top;
|
_total = _left + _top;
|
||||||
_calculateAngle();
|
_calculateAngle();
|
||||||
_calculateScale();
|
_calculateScale();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue