From d15dce01b3d977a5b831c9f41e3b88eb8023ec84 Mon Sep 17 00:00:00 2001 From: Juan Alvarez Date: Fri, 14 Jul 2023 15:04:14 -0500 Subject: [PATCH] added default swipe curve parameter in constructor --- lib/src/animation/animation.dart | 3 ++- lib/src/swipable_stack.dart | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/src/animation/animation.dart b/lib/src/animation/animation.dart index 8cf0211..3827a10 100644 --- a/lib/src/animation/animation.dart +++ b/lib/src/animation/animation.dart @@ -23,6 +23,7 @@ extension _AnimationControllerX on AnimationController { Animation swipeAnimation({ required Offset startPosition, required Offset endPosition, + required Curve curve, }) { return Tween( begin: startPosition, @@ -30,7 +31,7 @@ extension _AnimationControllerX on AnimationController { ).animate( CurvedAnimation( parent: this, - curve: const Cubic(0.7, 1, 0.73, 1), + curve: curve, ), ); } diff --git a/lib/src/swipable_stack.dart b/lib/src/swipable_stack.dart index 33feb27..f0adc08 100644 --- a/lib/src/swipable_stack.dart +++ b/lib/src/swipable_stack.dart @@ -34,6 +34,7 @@ class SwipableStack extends StatefulWidget { this.allowVerticalSwipe = true, Curve? cancelAnimationCurve, Curve? rewindAnimationCurve, + Curve? swipeAnimationCurve, this.swipeAnchor, this.dragStartBehavior = DragStartBehavior.start, this.hitTestBehavior = HitTestBehavior.deferToChild, @@ -44,6 +45,8 @@ class SwipableStack extends StatefulWidget { cancelAnimationCurve ?? _defaultCancelAnimationCurve, rewindAnimationCurve = rewindAnimationCurve ?? _defaultRewindAnimationCurve, + swipeAnimationCurve = + swipeAnimationCurve ?? _defaultSwipeAnimationCurve, assert(0 <= viewFraction && viewFraction <= 1), assert(0 <= horizontalSwipeThreshold && horizontalSwipeThreshold <= 1), assert(0 <= verticalSwipeThreshold && verticalSwipeThreshold <= 1), @@ -108,6 +111,9 @@ class SwipableStack extends StatefulWidget { /// A curve to animate the card when rewinding the swipe. final Curve rewindAnimationCurve; + /// default curve to animate the card when programatically swiping cards. + final Curve swipeAnimationCurve; + /// The [DragStartBehavior] of the swipes. final DragStartBehavior dragStartBehavior; @@ -134,6 +140,8 @@ class SwipableStack extends StatefulWidget { static const _defaultStackClipBehaviour = Clip.hardEdge; + static final _defaultSwipeAnimationCurve = Cubic(0.7, 1, 0.73, 1); + static final _defaultCancelAnimationCurve = Sprung.custom( damping: 17, mass: 0.5, @@ -669,6 +677,7 @@ class _SwipableStackState extends State context: context, swipeDirection: swipeDirection, ), + curve: widget.swipeAnimationCurve, ); void animate() { @@ -736,6 +745,7 @@ class _SwipableStackState extends State context: context, swipeDirection: swipeDirection, ), + curve: widget.swipeAnimationCurve, ); void animate() {