feat(types): make the callbacks type-safe

This commit is contained in:
Ricardo Dalarme 2023-01-13 23:46:21 -03:00
parent 3d1235dc96
commit 1bd59b9946
2 changed files with 6 additions and 7 deletions

View File

@ -51,6 +51,8 @@ class _MyHomePageState extends State<MyHomePage> {
} else if (dir == AxisDirection.down) {
debugPrint('onDown ${(widget as CardView).text} $index');
}
return true;
},
),
Container(

View File

@ -13,19 +13,21 @@ const List<Alignment> cardsAlign = [
];
final List<Size> 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<Widget> 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<SwipeableCardsStack>
frontCardAlign = const Alignment(0.0, 0.001);
}
shouldAnimate ??= true;
if (shouldAnimate) {
animateCards();
}
@ -215,8 +214,6 @@ class _SwipeableCardsStackState extends State<SwipeableCardsStack>
});
}
shouldAnimate ??= true;
if (shouldAnimate) {
animateCards();
}