Compare commits
1 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
bbf19cd498 |
|
|
@ -35,3 +35,5 @@ typedef CardSwiperOnUndo = bool Function(
|
||||||
int currentIndex,
|
int currentIndex,
|
||||||
CardSwiperDirection direction,
|
CardSwiperDirection direction,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
typedef CardSwiperOnTap = FutureOr<void> Function();
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,9 @@ class CardSwiper extends StatefulWidget {
|
||||||
/// Callback function that is called when the swiper is disabled.
|
/// Callback function that is called when the swiper is disabled.
|
||||||
final CardSwiperOnTapDisabled? onTapDisabled;
|
final CardSwiperOnTapDisabled? onTapDisabled;
|
||||||
|
|
||||||
|
/// Callback function that is called when the card is tapped (will not trigger from swipe movement)
|
||||||
|
final CardSwiperOnTap? onTap;
|
||||||
|
|
||||||
/// Defined the directions in which the card is allowed to be swiped.
|
/// Defined the directions in which the card is allowed to be swiped.
|
||||||
/// Defaults to [AllowedSwipeDirection.all]
|
/// Defaults to [AllowedSwipeDirection.all]
|
||||||
final AllowedSwipeDirection allowedSwipeDirection;
|
final AllowedSwipeDirection allowedSwipeDirection;
|
||||||
|
|
@ -134,6 +137,7 @@ class CardSwiper extends StatefulWidget {
|
||||||
this.scale = 0.9,
|
this.scale = 0.9,
|
||||||
this.isDisabled = false,
|
this.isDisabled = false,
|
||||||
this.onTapDisabled,
|
this.onTapDisabled,
|
||||||
|
this.onTap,
|
||||||
this.onSwipe,
|
this.onSwipe,
|
||||||
this.onEnd,
|
this.onEnd,
|
||||||
this.onSwipeDirectionChange,
|
this.onSwipeDirectionChange,
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ class _CardSwiperState<T extends Widget> extends State<CardSwiper>
|
||||||
if (widget.isDisabled) {
|
if (widget.isDisabled) {
|
||||||
await widget.onTapDisabled?.call();
|
await widget.onTapDisabled?.call();
|
||||||
}
|
}
|
||||||
|
await widget.onTap?.call();
|
||||||
},
|
},
|
||||||
onPanStart: (tapInfo) {
|
onPanStart: (tapInfo) {
|
||||||
if (!widget.isDisabled) {
|
if (!widget.isDisabled) {
|
||||||
|
|
|
||||||
|
|
@ -634,5 +634,28 @@ void main() {
|
||||||
|
|
||||||
expect(find.card(0), findsOneWidget);
|
expect(find.card(0), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('when tapping a card, expect callback', (WidgetTester tester) async {
|
||||||
|
final swiperKey = GlobalKey();
|
||||||
|
var isCalled = false;
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
CardSwiper(
|
||||||
|
key: swiperKey,
|
||||||
|
cardsCount: 3,
|
||||||
|
numberOfCardsDisplayed: 1,
|
||||||
|
onTap: () {
|
||||||
|
isCalled = true;
|
||||||
|
},
|
||||||
|
cardBuilder: genericBuilder,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.dragDown(swiperKey);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(isCalled, true);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue