From 92cab10c8fe72737edf84ee356a39d262074e96f Mon Sep 17 00:00:00 2001 From: MohammadAminAhmadi <64678866+MohammadAminAhmadi@users.noreply.github.com> Date: Wed, 10 May 2023 12:47:06 +0330 Subject: [PATCH] Update swipe_detector.dart 1. Do not include unwanted 2. Do not include diagonal movement --- lib/src/swipe_detector.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/src/swipe_detector.dart b/lib/src/swipe_detector.dart index 1bcc412..5d233f3 100644 --- a/lib/src/swipe_detector.dart +++ b/lib/src/swipe_detector.dart @@ -162,6 +162,7 @@ class _SwipeDetectorState extends State { behavior: widget.behavior, onPanStart: (details) { _startPosition = details.globalPosition; + _updatePosition = details.globalPosition; // for clicks }, onPanUpdate: (details) { _updatePosition = details.globalPosition; @@ -180,11 +181,14 @@ class _SwipeDetectorState extends State { final offset = _updatePosition - _startPosition; final direction = _getSwipeDirection(offset); - widget.onSwipe?.call( - direction, - offset, - ); - + final d = offset.distanceSquared; + final c = (offset.dx / offset.dy).abs(); + if (d > 1000 && (c > 1.2 || c < 0.8)) { + widget.onSwipe?.call( + direction, + offset, + ); + } switch (direction) { case SwipeDirection.up: widget.onSwipeUp?.call(offset);