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

Fixed several issues #1

Merged
merged 1 commit into from Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 33 additions & 20 deletions lib/src/cards.dart
Expand Up @@ -98,7 +98,7 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
// 前面的卡片
Widget _frontCard(BoxConstraints constraints) {
Widget child =
_frontCardIndex < _cards.length ? _cards[_frontCardIndex] : Container();
_frontCardIndex < _cards.length ? _cards[_frontCardIndex] : Container();
bool forward = _cardChangeController.status == AnimationStatus.forward;
bool reverse = _cardReverseController.status == AnimationStatus.forward;

Expand Down Expand Up @@ -314,10 +314,13 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
_frontCardIndex++;
_resetFrontCard();
if (widget.onForward != null && widget.onForward is Function) {
int _index = _frontCardIndex - 1 > 0 ? _frontCardIndex - 1 : 0;
SwipeInfo? info = _swipeInfoList.isNotEmpty ? _swipeInfoList[_index] : SwipeInfo(-1, SwipeDirection.None);
widget.onForward!(
_frontCardIndex,
_swipeInfoList[_frontCardIndex - 1],
info,
);

}

if (widget.onEnd != null &&
Expand All @@ -329,8 +332,9 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {

// Back animation callback
void _backCallback() {
_frontCardIndex++;
_resetFrontCard();
_swipeInfoList.removeLast();
// _swipeInfoList.removeLast();
if (widget.onBack != null && widget.onBack is Function) {
int index = _frontCardIndex > 0 ? _frontCardIndex - 1 : 0;
SwipeInfo info = _swipeInfoList.isNotEmpty
Expand All @@ -339,6 +343,13 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {

widget.onBack!(_frontCardIndex, info);
}


if (widget.onEnd != null &&
widget.onEnd is Function &&
_frontCardIndex >= _cards.length) {
widget.onEnd!();
}
}

// 重置最前面卡片的位置
Expand Down Expand Up @@ -402,8 +413,10 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
_runChangeOrderAnimation();
if (isSwipeLeft) {
_swipeInfoList.add(SwipeInfo(_frontCardIndex, SwipeDirection.Left));
_backCallback();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is breaking compared to the original package, as _backCallback() was used for reversing the stack IIRC

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmh, maybe

But it's strange, they use the backward to signal a swipe left, but also reverse the stack. Which are two different thing imho

} else {
_swipeInfoList.add(SwipeInfo(_frontCardIndex, SwipeDirection.Right));
_forwardCallback();
}
} else {
_runReboundAnimation(details.velocity.pixelsPerSecond, size);
Expand Down Expand Up @@ -435,7 +448,7 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
..addListener(() => setState(() {}))
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
_forwardCallback();
// _forwardCallback();
}
});

Expand All @@ -449,7 +462,7 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
if (status == AnimationStatus.forward) {
_frontCardIndex--;
} else if (status == AnimationStatus.completed) {
_backCallback();
//_backCallback();
}
});

Expand All @@ -458,10 +471,10 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
vsync: this,
duration: Duration(milliseconds: widget.delaySlideFor),
)..addListener(() {
setState(() {
_frontCardAlignment = _reboundAnimation.value;
});
setState(() {
_frontCardAlignment = _reboundAnimation.value;
});
});
}

@override
Expand Down Expand Up @@ -492,18 +505,18 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
// 使用一个 SizedBox 覆盖父元素整个区域
_cardChangeController.status != AnimationStatus.forward
? SizedBox.expand(
child: GestureDetector(
onPanDown: (DragDownDetails details) {
_stop();
},
onPanUpdate: (DragUpdateDetails details) {
_updateFrontCardAlignment(details, size);
},
onPanEnd: (DragEndDetails details) {
_judgeRunAnimation(details, size);
},
),
)
child: GestureDetector(
onPanDown: (DragDownDetails details) {
_stop();
},
onPanUpdate: (DragUpdateDetails details) {
_updateFrontCardAlignment(details, size);
},
onPanEnd: (DragEndDetails details) {
_judgeRunAnimation(details, size);
},
),
)
: IgnorePointer(),
],
);
Expand Down