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]
|
## [4.1.0]
|
||||||
|
|
||||||
|
- Changes `onSwipe` and `onEnd` callbacks to be FutureOr.
|
||||||
|
|
||||||
|
## [4.1.0]
|
||||||
|
|
||||||
- Adds option to undo swipes.
|
- Adds option to undo swipes.
|
||||||
|
|
||||||
## [4.0.2]
|
## [4.0.2]
|
||||||
|
|
|
||||||
|
|
@ -242,9 +242,9 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
|
||||||
child: widget.cardBuilder(context, _currentIndex!),
|
child: widget.cardBuilder(context, _currentIndex!),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
if (widget.isDisabled) {
|
if (widget.isDisabled) {
|
||||||
widget.onTapDisabled?.call();
|
await widget.onTapDisabled?.call();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onPanStart: (tapInfo) {
|
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) {
|
if (status == AnimationStatus.completed) {
|
||||||
switch (_swipeType) {
|
switch (_swipeType) {
|
||||||
case SwipeType.swipe:
|
case SwipeType.swipe:
|
||||||
_handleCompleteSwipe();
|
await _handleCompleteSwipe();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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 isLastCard = _currentIndex! == widget.cardsCount - 1;
|
||||||
final shouldCancelSwipe =
|
final shouldCancelSwipe = await widget.onSwipe
|
||||||
widget.onSwipe?.call(_currentIndex!, _nextIndex, _detectedDirection) ==
|
?.call(_currentIndex!, _nextIndex, _detectedDirection) ==
|
||||||
false;
|
false;
|
||||||
|
|
||||||
if (shouldCancelSwipe) {
|
if (shouldCancelSwipe) {
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter_card_swiper/src/enums.dart';
|
import 'package:flutter_card_swiper/src/enums.dart';
|
||||||
|
|
||||||
typedef CardSwiperOnSwipe = bool Function(
|
typedef CardSwiperOnSwipe = FutureOr<bool> Function(
|
||||||
int previousIndex,
|
int previousIndex,
|
||||||
int? currentIndex,
|
int? currentIndex,
|
||||||
CardSwiperDirection direction,
|
CardSwiperDirection direction,
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef CardSwiperOnEnd = void Function();
|
typedef CardSwiperOnEnd = FutureOr<void> Function();
|
||||||
|
|
||||||
typedef CardSwiperOnTapDisabled = void Function();
|
typedef CardSwiperOnTapDisabled = FutureOr<void> Function();
|
||||||
|
|
||||||
typedef CardSwiperOnUndo = bool Function(
|
typedef CardSwiperOnUndo = bool Function(
|
||||||
int? previousIndex,
|
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.
|
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
|
homepage: https://github.com/ricardodalarme/flutter_card_swiper
|
||||||
issue_tracker: https://github.com/ricardodalarme/flutter_card_swiper/issues
|
issue_tracker: https://github.com/ricardodalarme/flutter_card_swiper/issues
|
||||||
version: 4.1.0+2
|
version: 4.1.1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.12.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue