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:
parent
75d8ebe903
commit
095d46f21a
|
|
@ -1,3 +1,7 @@
|
||||||
|
## [4.1.3]
|
||||||
|
|
||||||
|
- Fix Swiping when `isDisabled` is `true` and triggered by the `controller`.
|
||||||
|
|
||||||
## [4.1.2]
|
## [4.1.2]
|
||||||
|
|
||||||
- Fixes the `isHorizontalSwipingEnabled` and `isVerticalSwipingEnabled`.
|
- Fixes the `isHorizontalSwipingEnabled` and `isVerticalSwipingEnabled`.
|
||||||
|
|
|
||||||
|
|
@ -391,7 +391,7 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
|
||||||
}
|
}
|
||||||
|
|
||||||
void _swipe(CardSwiperDirection direction) {
|
void _swipe(CardSwiperDirection direction) {
|
||||||
if (!_canSwipe) return;
|
if (_currentIndex == null) return;
|
||||||
|
|
||||||
_swipeType = SwipeType.swipe;
|
_swipeType = SwipeType.swipe;
|
||||||
_detectedDirection = direction;
|
_detectedDirection = direction;
|
||||||
|
|
|
||||||
|
|
@ -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.2
|
version: 4.1.3
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.12.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
|
|
||||||
|
|
@ -43,281 +43,298 @@ void main() {
|
||||||
expect(controller.state, CardSwiperState.undo);
|
expect(controller.state, CardSwiperState.undo);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('swipe() should swipe the card to the defined direction',
|
for (final isDisabled in [false, true]) {
|
||||||
(tester) async {
|
group('isDisabled=$isDisabled', () {
|
||||||
final controller = CardSwiperController();
|
testWidgets('swipe() should swipe the card to the defined direction',
|
||||||
var direction = CardSwiperDirection.none;
|
(tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
await tester.pumpApp(
|
await tester.pumpApp(
|
||||||
CardSwiper(
|
CardSwiper(
|
||||||
controller: controller,
|
isDisabled: isDisabled,
|
||||||
cardsCount: 10,
|
controller: controller,
|
||||||
cardBuilder: genericBuilder,
|
cardsCount: 10,
|
||||||
direction: CardSwiperDirection.top,
|
cardBuilder: genericBuilder,
|
||||||
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
direction: CardSwiperDirection.top,
|
||||||
direction = swipeDirection;
|
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
||||||
return true;
|
direction = swipeDirection;
|
||||||
},
|
return true;
|
||||||
),
|
},
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
|
||||||
controller.swipe();
|
controller.swipe();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(direction, CardSwiperDirection.top);
|
expect(direction, CardSwiperDirection.top);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('swipeLeft() should swipe the card to the left',
|
testWidgets('swipeLeft() should swipe the card to the left',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
final controller = CardSwiperController();
|
final controller = CardSwiperController();
|
||||||
var direction = CardSwiperDirection.none;
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
await tester.pumpApp(
|
await tester.pumpApp(
|
||||||
CardSwiper(
|
CardSwiper(
|
||||||
controller: controller,
|
isDisabled: isDisabled,
|
||||||
cardsCount: 10,
|
controller: controller,
|
||||||
cardBuilder: genericBuilder,
|
cardsCount: 10,
|
||||||
direction: CardSwiperDirection.left,
|
cardBuilder: genericBuilder,
|
||||||
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
direction: CardSwiperDirection.left,
|
||||||
direction = swipeDirection;
|
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
||||||
return true;
|
direction = swipeDirection;
|
||||||
},
|
return true;
|
||||||
),
|
},
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
|
||||||
controller.swipeLeft();
|
controller.swipeLeft();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(direction, CardSwiperDirection.left);
|
expect(direction, CardSwiperDirection.left);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('swipeRight() should swipe the card to the right',
|
testWidgets('swipeRight() should swipe the card to the right',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
final controller = CardSwiperController();
|
final controller = CardSwiperController();
|
||||||
var direction = CardSwiperDirection.none;
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
await tester.pumpApp(
|
await tester.pumpApp(
|
||||||
CardSwiper(
|
CardSwiper(
|
||||||
controller: controller,
|
isDisabled: isDisabled,
|
||||||
cardsCount: 10,
|
controller: controller,
|
||||||
cardBuilder: genericBuilder,
|
cardsCount: 10,
|
||||||
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
cardBuilder: genericBuilder,
|
||||||
direction = swipeDirection;
|
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
||||||
return true;
|
direction = swipeDirection;
|
||||||
},
|
return true;
|
||||||
),
|
},
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
|
||||||
controller.swipeRight();
|
controller.swipeRight();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(direction, CardSwiperDirection.right);
|
expect(direction, CardSwiperDirection.right);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('swipeTop() should swipe the card to the top', (tester) async {
|
testWidgets('swipeTop() should swipe the card to the top',
|
||||||
final controller = CardSwiperController();
|
(tester) async {
|
||||||
var direction = CardSwiperDirection.none;
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
await tester.pumpApp(
|
await tester.pumpApp(
|
||||||
CardSwiper(
|
CardSwiper(
|
||||||
controller: controller,
|
isDisabled: isDisabled,
|
||||||
cardsCount: 10,
|
controller: controller,
|
||||||
cardBuilder: genericBuilder,
|
cardsCount: 10,
|
||||||
direction: CardSwiperDirection.top,
|
cardBuilder: genericBuilder,
|
||||||
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
direction: CardSwiperDirection.top,
|
||||||
direction = swipeDirection;
|
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
||||||
return true;
|
direction = swipeDirection;
|
||||||
},
|
return true;
|
||||||
),
|
},
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
|
||||||
controller.swipeTop();
|
controller.swipeTop();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(direction, CardSwiperDirection.top);
|
expect(direction, CardSwiperDirection.top);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('swipeBottom() should swipe the card to the bottom',
|
testWidgets('swipeBottom() should swipe the card to the bottom',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
final controller = CardSwiperController();
|
final controller = CardSwiperController();
|
||||||
var direction = CardSwiperDirection.none;
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
await tester.pumpApp(
|
await tester.pumpApp(
|
||||||
CardSwiper(
|
CardSwiper(
|
||||||
controller: controller,
|
isDisabled: isDisabled,
|
||||||
cardsCount: 10,
|
controller: controller,
|
||||||
cardBuilder: genericBuilder,
|
cardsCount: 10,
|
||||||
direction: CardSwiperDirection.bottom,
|
cardBuilder: genericBuilder,
|
||||||
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
direction: CardSwiperDirection.bottom,
|
||||||
direction = swipeDirection;
|
onSwipe: (oldIndex, currentIndex, swipeDirection) {
|
||||||
return true;
|
direction = swipeDirection;
|
||||||
},
|
return true;
|
||||||
),
|
},
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
|
||||||
controller.swipeBottom();
|
controller.swipeBottom();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(direction, CardSwiperDirection.bottom);
|
expect(direction, CardSwiperDirection.bottom);
|
||||||
});
|
});
|
||||||
|
|
||||||
group('undo()', () {
|
group('undo()', () {
|
||||||
testWidgets('should undo the last swipe', (tester) async {
|
testWidgets('should undo the last swipe', (tester) async {
|
||||||
final controller = CardSwiperController();
|
final controller = CardSwiperController();
|
||||||
|
|
||||||
await tester.pumpApp(
|
await tester.pumpApp(
|
||||||
CardSwiper(
|
CardSwiper(
|
||||||
controller: controller,
|
isDisabled: isDisabled,
|
||||||
cardsCount: 10,
|
controller: controller,
|
||||||
cardBuilder: genericBuilder,
|
cardsCount: 10,
|
||||||
),
|
cardBuilder: genericBuilder,
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
|
||||||
controller.swipe();
|
controller.swipe();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.card(1), findsOneWidget);
|
expect(find.card(1), findsOneWidget);
|
||||||
|
|
||||||
controller.undo();
|
controller.undo();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
expect(find.card(0), findsOneWidget);
|
expect(find.card(0), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should undo the last swipe left', (tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
CardSwiper(
|
||||||
|
isDisabled: isDisabled,
|
||||||
|
controller: controller,
|
||||||
|
cardsCount: 10,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
direction = swipeDirection;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipeLeft();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.card(1), findsOneWidget);
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.card(0), findsOneWidget);
|
||||||
|
expect(direction, CardSwiperDirection.left);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should undo the last swipe right', (tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
CardSwiper(
|
||||||
|
isDisabled: isDisabled,
|
||||||
|
controller: controller,
|
||||||
|
cardsCount: 10,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
direction = swipeDirection;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipeRight();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.card(1), findsOneWidget);
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.card(0), findsOneWidget);
|
||||||
|
expect(direction, CardSwiperDirection.right);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should undo the last swipe top', (tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
CardSwiper(
|
||||||
|
isDisabled: isDisabled,
|
||||||
|
controller: controller,
|
||||||
|
cardsCount: 10,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
direction = swipeDirection;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipeTop();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.card(1), findsOneWidget);
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.card(0), findsOneWidget);
|
||||||
|
expect(direction, CardSwiperDirection.top);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('should undo the last swipe bottom', (tester) async {
|
||||||
|
final controller = CardSwiperController();
|
||||||
|
var direction = CardSwiperDirection.none;
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
CardSwiper(
|
||||||
|
isDisabled: isDisabled,
|
||||||
|
controller: controller,
|
||||||
|
cardsCount: 10,
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
direction = swipeDirection;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipeBottom();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.card(1), findsOneWidget);
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.card(0), findsOneWidget);
|
||||||
|
expect(direction, CardSwiperDirection.bottom);
|
||||||
|
});
|
||||||
|
|
||||||
|
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,
|
||||||
|
onUndo: (_, __, swipeDirection) {
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
controller.swipe();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
controller.undo();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.card(0), findsNothing);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
testWidgets('should undo the last swipe left', (tester) async {
|
|
||||||
final controller = CardSwiperController();
|
|
||||||
var direction = CardSwiperDirection.none;
|
|
||||||
|
|
||||||
await tester.pumpApp(
|
|
||||||
CardSwiper(
|
|
||||||
controller: controller,
|
|
||||||
cardsCount: 10,
|
|
||||||
cardBuilder: genericBuilder,
|
|
||||||
onUndo: (_, __, swipeDirection) {
|
|
||||||
direction = swipeDirection;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
controller.swipeLeft();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
expect(find.card(1), findsOneWidget);
|
|
||||||
|
|
||||||
controller.undo();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
expect(find.card(0), findsOneWidget);
|
|
||||||
expect(direction, CardSwiperDirection.left);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('should undo the last swipe right', (tester) async {
|
|
||||||
final controller = CardSwiperController();
|
|
||||||
var direction = CardSwiperDirection.none;
|
|
||||||
|
|
||||||
await tester.pumpApp(
|
|
||||||
CardSwiper(
|
|
||||||
controller: controller,
|
|
||||||
cardsCount: 10,
|
|
||||||
cardBuilder: genericBuilder,
|
|
||||||
onUndo: (_, __, swipeDirection) {
|
|
||||||
direction = swipeDirection;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
controller.swipeRight();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
expect(find.card(1), findsOneWidget);
|
|
||||||
|
|
||||||
controller.undo();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
expect(find.card(0), findsOneWidget);
|
|
||||||
expect(direction, CardSwiperDirection.right);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('should undo the last swipe top', (tester) async {
|
|
||||||
final controller = CardSwiperController();
|
|
||||||
var direction = CardSwiperDirection.none;
|
|
||||||
|
|
||||||
await tester.pumpApp(
|
|
||||||
CardSwiper(
|
|
||||||
controller: controller,
|
|
||||||
cardsCount: 10,
|
|
||||||
cardBuilder: genericBuilder,
|
|
||||||
onUndo: (_, __, swipeDirection) {
|
|
||||||
direction = swipeDirection;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
controller.swipeTop();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
expect(find.card(1), findsOneWidget);
|
|
||||||
|
|
||||||
controller.undo();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
expect(find.card(0), findsOneWidget);
|
|
||||||
expect(direction, CardSwiperDirection.top);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('should undo the last swipe bottom', (tester) async {
|
|
||||||
final controller = CardSwiperController();
|
|
||||||
var direction = CardSwiperDirection.none;
|
|
||||||
|
|
||||||
await tester.pumpApp(
|
|
||||||
CardSwiper(
|
|
||||||
controller: controller,
|
|
||||||
cardsCount: 10,
|
|
||||||
cardBuilder: genericBuilder,
|
|
||||||
onUndo: (_, __, swipeDirection) {
|
|
||||||
direction = swipeDirection;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
controller.swipeBottom();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
expect(find.card(1), findsOneWidget);
|
|
||||||
|
|
||||||
controller.undo();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
expect(find.card(0), findsOneWidget);
|
|
||||||
expect(direction, CardSwiperDirection.bottom);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWidgets('should not undo if onUndo returns false', (tester) async {
|
|
||||||
final controller = CardSwiperController();
|
|
||||||
|
|
||||||
await tester.pumpApp(
|
|
||||||
CardSwiper(
|
|
||||||
controller: controller,
|
|
||||||
cardsCount: 10,
|
|
||||||
cardBuilder: genericBuilder,
|
|
||||||
onUndo: (_, __, swipeDirection) {
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
controller.swipe();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
controller.undo();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
expect(find.card(0), findsNothing);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue