forked from inex/swipe_to_action
Compare commits
No commits in common. "add-max-offset-listener" and "master" have entirely different histories.
add-max-of
...
master
|
@ -19,8 +19,6 @@ typedef SwipeDirectionCallback = void Function(SwipeDirection direction);
|
|||
/// Used by [Swipeable.confirmSwipe].
|
||||
typedef ConfirmSwipeCallback = Future<bool> Function(SwipeDirection direction);
|
||||
|
||||
typedef OnOverScrollTheMaxOffset = void Function();
|
||||
|
||||
/// The direction in which a [Swipeable] can be swiped.
|
||||
enum SwipeDirection {
|
||||
/// The [Swipeable] can be swiped by dragging either left or right.
|
||||
|
@ -60,13 +58,11 @@ class Swipeable extends StatefulWidget {
|
|||
this.movementDuration = const Duration(milliseconds: 200),
|
||||
this.crossAxisEndOffset = 0.0,
|
||||
this.dragStartBehavior = DragStartBehavior.start,
|
||||
this.swipeIntensity = 1.0,
|
||||
this.allowedPointerKinds = const {
|
||||
PointerDeviceKind.invertedStylus,
|
||||
PointerDeviceKind.stylus,
|
||||
PointerDeviceKind.touch
|
||||
},
|
||||
this.onOverScrollTheMaxOffset,
|
||||
}) : assert(secondaryBackground == null || background != null),
|
||||
super(key: key);
|
||||
|
||||
|
@ -158,13 +154,6 @@ class Swipeable extends StatefulWidget {
|
|||
/// * [DragGestureRecognizer.dragStartBehavior], which gives an example for the different behaviors.
|
||||
final DragStartBehavior dragStartBehavior;
|
||||
|
||||
///If the swipeIntensity is low, the message requires a stronger swipe.
|
||||
///The default value is set to 1. Consider increasing the swipeIntensity to make it easier for users to swipe.
|
||||
final double swipeIntensity;
|
||||
|
||||
/// When the user scrolls beyond the maximum offset, the function will be invoked, and it will only be called once.
|
||||
final OnOverScrollTheMaxOffset? onOverScrollTheMaxOffset;
|
||||
|
||||
@override
|
||||
_SwipeableState createState() => _SwipeableState();
|
||||
}
|
||||
|
@ -202,19 +191,6 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
|
|||
_moveController = AnimationController(duration: widget.movementDuration, vsync: this)
|
||||
..addStatusListener(_handleDismissStatusChanged);
|
||||
_updateMoveAnimation();
|
||||
_moveController.addListener(() {
|
||||
|
||||
if (!isInSwipe) {
|
||||
isSwipeAnimationRunning = true;
|
||||
}
|
||||
|
||||
if (isSwipeAnimationRunning && _moveController.value >= widget.maxOffset) {
|
||||
if (widget.onOverScrollTheMaxOffset != null) {
|
||||
widget.onOverScrollTheMaxOffset!();
|
||||
}
|
||||
isSwipeAnimationRunning = false;
|
||||
}
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
@ -223,7 +199,6 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
|
|||
late Animation<Offset> _moveAnimation;
|
||||
|
||||
double _dragExtent = 0.0;
|
||||
bool isSwipeAnimationRunning = false;
|
||||
bool _dragUnderway = false;
|
||||
Size? _sizePriorToCollapse;
|
||||
|
||||
|
@ -232,8 +207,6 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
|
|||
@override
|
||||
bool get wantKeepAlive => _moveController.isAnimating == true;
|
||||
|
||||
bool get isInSwipe => _moveController.value != 0;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_moveController.dispose();
|
||||
|
@ -288,7 +261,7 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
|
|||
return;
|
||||
}
|
||||
|
||||
final delta = (details.primaryDelta ?? 0.0) * widget.swipeIntensity;
|
||||
final delta = details.primaryDelta ?? 0.0;
|
||||
final oldDragExtent = _dragExtent;
|
||||
switch (widget.direction) {
|
||||
case SwipeDirection.none:
|
||||
|
@ -378,7 +351,7 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
|
|||
return;
|
||||
}
|
||||
_dragUnderway = false;
|
||||
if (_moveController.value >= widget.maxOffset && await _confirmStartSwipeAnimation() == true) {
|
||||
if (_moveController.isCompleted && await _confirmStartSwipeAnimation() == true) {
|
||||
_startSwipeAnimation();
|
||||
return;
|
||||
}
|
||||
|
@ -402,7 +375,12 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
|
|||
break;
|
||||
case _FlingGestureKind.none:
|
||||
if (!_moveController.isDismissed) {
|
||||
await _moveController.reverse();
|
||||
// we already know it's not completed, we check that above
|
||||
if (_moveController.value > (widget.dismissThresholds[_swipeDirection] ?? _kDismissThreshold)) {
|
||||
await _moveController.forward();
|
||||
} else {
|
||||
await _moveController.reverse();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -428,6 +406,7 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
|
|||
}
|
||||
|
||||
void _startSwipeAnimation() {
|
||||
assert(_moveController.isCompleted);
|
||||
assert(_sizePriorToCollapse == null);
|
||||
|
||||
final direction = _swipeDirection;
|
||||
|
@ -449,7 +428,7 @@ class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, Au
|
|||
background = widget.secondaryBackground;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Widget content = SlideTransition(
|
||||
position: _moveAnimation,
|
||||
child: widget.child,
|
||||
|
|
Loading…
Reference in a new issue