feat(callbacks): change `onSwipe` and `onEnd` to be FutureOr (#14)
This commit is contained in:
parent
61aa3cdde7
commit
946d560b6f
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -242,9 +242,9 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
|
|||
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<T extends Widget> extends State<CardSwiper>
|
|||
}
|
||||
}
|
||||
|
||||
void _animationStatusListener(AnimationStatus status) {
|
||||
Future<void> _animationStatusListener(AnimationStatus status) async {
|
||||
if (status == AnimationStatus.completed) {
|
||||
switch (_swipeType) {
|
||||
case SwipeType.swipe:
|
||||
_handleCompleteSwipe();
|
||||
await _handleCompleteSwipe();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -346,10 +346,10 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
|
|||
}
|
||||
}
|
||||
|
||||
void _handleCompleteSwipe() {
|
||||
Future<void> _handleCompleteSwipe() async {
|
||||
final isLastCard = _currentIndex! == widget.cardsCount - 1;
|
||||
final shouldCancelSwipe =
|
||||
widget.onSwipe?.call(_currentIndex!, _nextIndex, _detectedDirection) ==
|
||||
final shouldCancelSwipe = await widget.onSwipe
|
||||
?.call(_currentIndex!, _nextIndex, _detectedDirection) ==
|
||||
false;
|
||||
|
||||
if (shouldCancelSwipe) {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_card_swiper/src/enums.dart';
|
||||
|
||||
typedef CardSwiperOnSwipe = bool Function(
|
||||
typedef CardSwiperOnSwipe = FutureOr<bool> Function(
|
||||
int previousIndex,
|
||||
int? currentIndex,
|
||||
CardSwiperDirection direction,
|
||||
);
|
||||
|
||||
typedef CardSwiperOnEnd = void Function();
|
||||
typedef CardSwiperOnEnd = FutureOr<void> Function();
|
||||
|
||||
typedef CardSwiperOnTapDisabled = void Function();
|
||||
typedef CardSwiperOnTapDisabled = FutureOr<void> Function();
|
||||
|
||||
typedef CardSwiperOnUndo = bool Function(
|
||||
int? previousIndex,
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue