diff --git a/CHANGELOG.md b/CHANGELOG.md index 0eb1811..7244029 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [4.1.0] +- Changes `onSwipe` and `onEnd` callbacks to be FutureOr. + +## [4.1.0] + - Adds option to undo swipes. ## [4.0.2] diff --git a/lib/src/card_swiper.dart b/lib/src/card_swiper.dart index 4df6b6b..3dad38b 100644 --- a/lib/src/card_swiper.dart +++ b/lib/src/card_swiper.dart @@ -242,9 +242,9 @@ class _CardSwiperState extends State child: widget.cardBuilder(context, _currentIndex!), ), ), - onTap: () { + onTap: () async { if (widget.isDisabled) { - widget.onTapDisabled?.call(); + await widget.onTapDisabled?.call(); } }, onPanStart: (tapInfo) { @@ -332,11 +332,11 @@ class _CardSwiperState extends State } } - void _animationStatusListener(AnimationStatus status) { + Future _animationStatusListener(AnimationStatus status) async { if (status == AnimationStatus.completed) { switch (_swipeType) { case SwipeType.swipe: - _handleCompleteSwipe(); + await _handleCompleteSwipe(); break; default: break; @@ -346,11 +346,11 @@ class _CardSwiperState extends State } } - void _handleCompleteSwipe() { + Future _handleCompleteSwipe() async { final isLastCard = _currentIndex! == widget.cardsCount - 1; - final shouldCancelSwipe = - widget.onSwipe?.call(_currentIndex!, _nextIndex, _detectedDirection) == - false; + final shouldCancelSwipe = await widget.onSwipe + ?.call(_currentIndex!, _nextIndex, _detectedDirection) == + false; if (shouldCancelSwipe) { return; diff --git a/lib/src/typedefs.dart b/lib/src/typedefs.dart index 311d1fe..d628f6f 100644 --- a/lib/src/typedefs.dart +++ b/lib/src/typedefs.dart @@ -1,14 +1,16 @@ +import 'dart:async'; + import 'package:flutter_card_swiper/src/enums.dart'; -typedef CardSwiperOnSwipe = bool Function( +typedef CardSwiperOnSwipe = FutureOr Function( int previousIndex, int? currentIndex, CardSwiperDirection direction, ); -typedef CardSwiperOnEnd = void Function(); +typedef CardSwiperOnEnd = FutureOr Function(); -typedef CardSwiperOnTapDisabled = void Function(); +typedef CardSwiperOnTapDisabled = FutureOr Function(); typedef CardSwiperOnUndo = bool Function( int? previousIndex, diff --git a/pubspec.yaml b/pubspec.yaml index 397d5a8..d8611dd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_card_swiper description: This is a Tinder-like card swiper package. It allows you to swipe left, right, up, and down and define your own business logic for each direction. homepage: https://github.com/ricardodalarme/flutter_card_swiper issue_tracker: https://github.com/ricardodalarme/flutter_card_swiper/issues -version: 4.1.0+2 +version: 4.1.1 environment: sdk: ">=2.12.0 <3.0.0"