fix: swiping through the `controller` when `isDisable` is `true` (#15)

- When isDisable was true it wasn't possible to swipe using the controller
This commit is contained in:
kzrnm 2023-04-18 10:33:04 +09:00 committed by GitHub
parent 75d8ebe903
commit 095d46f21a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 273 additions and 252 deletions

View File

@ -1,3 +1,7 @@
## [4.1.3]
- Fix Swiping when `isDisabled` is `true` and triggered by the `controller`.
## [4.1.2]
- Fixes the `isHorizontalSwipingEnabled` and `isVerticalSwipingEnabled`.

View File

@ -391,7 +391,7 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
}
void _swipe(CardSwiperDirection direction) {
if (!_canSwipe) return;
if (_currentIndex == null) return;
_swipeType = SwipeType.swipe;
_detectedDirection = direction;

View File

@ -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.2
version: 4.1.3
environment:
sdk: ">=2.12.0 <3.0.0"

View File

@ -43,6 +43,8 @@ void main() {
expect(controller.state, CardSwiperState.undo);
});
for (final isDisabled in [false, true]) {
group('isDisabled=$isDisabled', () {
testWidgets('swipe() should swipe the card to the defined direction',
(tester) async {
final controller = CardSwiperController();
@ -50,6 +52,7 @@ void main() {
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -74,6 +77,7 @@ void main() {
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -98,6 +102,7 @@ void main() {
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -114,12 +119,14 @@ void main() {
expect(direction, CardSwiperDirection.right);
});
testWidgets('swipeTop() should swipe the card to the top', (tester) async {
testWidgets('swipeTop() should swipe the card to the top',
(tester) async {
final controller = CardSwiperController();
var direction = CardSwiperDirection.none;
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -144,6 +151,7 @@ void main() {
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -167,6 +175,7 @@ void main() {
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -190,6 +199,7 @@ void main() {
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -218,6 +228,7 @@ void main() {
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -246,6 +257,7 @@ void main() {
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -274,6 +286,7 @@ void main() {
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -296,11 +309,13 @@ void main() {
expect(direction, CardSwiperDirection.bottom);
});
testWidgets('should not undo if onUndo returns false', (tester) async {
testWidgets('should not undo if onUndo returns false',
(tester) async {
final controller = CardSwiperController();
await tester.pumpApp(
CardSwiper(
isDisabled: isDisabled,
controller: controller,
cardsCount: 10,
cardBuilder: genericBuilder,
@ -321,3 +336,5 @@ void main() {
});
});
}
});
}