From 712685e20cc761bcf49aad76d824f4f75e14ab93 Mon Sep 17 00:00:00 2001 From: Ricardo Dalarme Date: Sun, 15 Jan 2023 22:31:42 -0300 Subject: [PATCH] feat: make swipe type an enum --- lib/card_swiper.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/card_swiper.dart b/lib/card_swiper.dart index 75ddaf2..6378037 100644 --- a/lib/card_swiper.dart +++ b/lib/card_swiper.dart @@ -70,7 +70,7 @@ class _CardSwiperState extends State int _currentIndex = 0; - int _swipeTyp = 0; // 1 = swipe, 3 = goBack + SwipeType _swipeTyp = SwipeType.none; bool _tapOnTop = false; //position of starting drag point on card late AnimationController _animationController; @@ -158,7 +158,7 @@ class _CardSwiperState extends State //when status of controller changes if (status == AnimationStatus.completed) { setState(() { - if (_swipeTyp == 1) { + if (_swipeTyp == SwipeType.swipe) { widget.onSwipe(_currentIndex, detectedDirection); if (_isLastCard) { @@ -175,7 +175,7 @@ class _CardSwiperState extends State _angle = 0; _scale = 0.9; _difference = 40; - _swipeTyp = 0; + _swipeTyp = SwipeType.none; }); } }); @@ -311,7 +311,7 @@ class _CardSwiperState extends State //moves the card away to the left or right void _swipeHorizontal(BuildContext context) { setState(() { - _swipeTyp = 1; + _swipeTyp = SwipeType.swipe; _leftAnimation = Tween( begin: _left, end: (_left == 0) @@ -346,7 +346,7 @@ class _CardSwiperState extends State //moves the card away to the top or bottom void _swipeVertical(BuildContext context) { setState(() { - _swipeTyp = 1; + _swipeTyp = SwipeType.swipe; _leftAnimation = Tween( begin: _left, end: _left + _left, @@ -381,7 +381,7 @@ class _CardSwiperState extends State //moves the card back to starting position void _goBack(BuildContext context) { setState(() { - _swipeTyp = 3; + _swipeTyp = SwipeType.back; _leftAnimation = Tween( begin: _left, end: 0, @@ -432,3 +432,5 @@ class CardSwiperController extends ChangeNotifier { enum CardSwiperState { swipe, swipeLeft, swipeRight } enum CardSwiperDirection { none, left, right, top, bottom } + +enum SwipeType { none, swipe, back }