From 1bd59b994606d8ceb1ea3198c68119a28a08b948 Mon Sep 17 00:00:00 2001 From: Ricardo Dalarme Date: Fri, 13 Jan 2023 23:46:21 -0300 Subject: [PATCH] feat(types): make the callbacks type-safe --- example/lib/main.dart | 2 ++ lib/src/swipeable_cards_stack.dart | 11 ++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 6d47364..b15244f 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -51,6 +51,8 @@ class _MyHomePageState extends State { } else if (dir == AxisDirection.down) { debugPrint('onDown ${(widget as CardView).text} $index'); } + + return true; }, ), Container( diff --git a/lib/src/swipeable_cards_stack.dart b/lib/src/swipeable_cards_stack.dart index 6f88cf4..0f0f599 100644 --- a/lib/src/swipeable_cards_stack.dart +++ b/lib/src/swipeable_cards_stack.dart @@ -13,19 +13,21 @@ const List cardsAlign = [ ]; final List cardsSize = List.filled(3, const Size(1, 1)); +typedef OnCardSwiped = bool Function( + AxisDirection dir, int index, Widget? widget); + class SwipeableCardsStack extends StatefulWidget { final SwipeableCardsStackController? cardController; //First 3 widgets final List items; - final Function? onCardSwiped; + final OnCardSwiped? onCardSwiped; final double cardWidthTopMul; final double cardWidthMiddleMul; final double cardWidthBottomMul; final double cardHeightTopMul; final double cardHeightMiddleMul; final double cardHeightBottomMul; - final Function? appendItemCallback; final bool enableSwipeUp; final bool enableSwipeDown; final bool enableSwipeLeft; @@ -43,7 +45,6 @@ class SwipeableCardsStack extends StatefulWidget { this.cardHeightTopMul = 0.6, this.cardHeightMiddleMul = 0.55, this.cardHeightBottomMul = 0.5, - this.appendItemCallback, this.enableSwipeUp = true, this.enableSwipeDown = true, this.enableSwipeLeft = true, @@ -98,8 +99,6 @@ class _SwipeableCardsStackState extends State frontCardAlign = const Alignment(0.0, 0.001); } - shouldAnimate ??= true; - if (shouldAnimate) { animateCards(); } @@ -215,8 +214,6 @@ class _SwipeableCardsStackState extends State }); } - shouldAnimate ??= true; - if (shouldAnimate) { animateCards(); }