From ed0206f06ee23fc199251ec866ecc9718ed44332 Mon Sep 17 00:00:00 2001 From: Ricardo Dalarme Date: Fri, 27 Jan 2023 13:30:00 -0300 Subject: [PATCH] refactor(logic): simplify some operations --- lib/src/card_swiper.dart | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/src/card_swiper.dart b/lib/src/card_swiper.dart index faa1f91..be14d2a 100644 --- a/lib/src/card_swiper.dart +++ b/lib/src/card_swiper.dart @@ -266,9 +266,8 @@ class _CardSwiperState extends State void _calculateAngle() { if (_angle <= _maxAngle && _angle >= -_maxAngle) { - _tapOnTop - ? _angle = (_maxAngle / 100) * (_left / 10) - : _angle = (_maxAngle / 100) * (_left / 10) * -1; + _angle = (_maxAngle / 100) * (_left / 10); + if (_tapOnTop) _angle *= -1; } } @@ -325,13 +324,10 @@ class _CardSwiperState extends State void _swipeHorizontal(BuildContext context) { _leftAnimation = Tween( begin: _left, - end: (_left == 0) - ? (widget.direction == CardSwiperDirection.right) - ? MediaQuery.of(context).size.width - : -MediaQuery.of(context).size.width - : (_left > widget.threshold) - ? MediaQuery.of(context).size.width - : -MediaQuery.of(context).size.width, + end: (_left == 0 && widget.direction == CardSwiperDirection.right) || + _left > widget.threshold + ? MediaQuery.of(context).size.width + : -MediaQuery.of(context).size.width, ).animate(_animationController); _topAnimation = Tween( begin: _top, @@ -363,13 +359,10 @@ class _CardSwiperState extends State ).animate(_animationController); _topAnimation = Tween( begin: _top, - end: (_top == 0) - ? (widget.direction == CardSwiperDirection.bottom) - ? MediaQuery.of(context).size.height - : -MediaQuery.of(context).size.height - : (_top > widget.threshold) - ? MediaQuery.of(context).size.height - : -MediaQuery.of(context).size.height, + end: (_top == 0 && widget.direction == CardSwiperDirection.bottom) || + _top > widget.threshold + ? MediaQuery.of(context).size.height + : -MediaQuery.of(context).size.height, ).animate(_animationController); _scaleAnimation = Tween( begin: _scale,