TinderSwapCard constructor

TinderSwapCard({
  1. required CardBuilder cardBuilder,
  2. required int totalNum,
  3. AmassOrientation orientation = AmassOrientation.bottom,
  4. int stackNum = 3,
  5. int animDuration = 800,
  6. double swipeEdge = 3.0,
  7. double swipeEdgeVertical = 8.0,
  8. bool swipeUp = false,
  9. bool swipeDown = false,
  10. double? maxWidth,
  11. double? maxHeight,
  12. double? minWidth,
  13. double? minHeight,
  14. bool allowVerticalMovement = true,
  15. CardController? cardController,
  16. CardSwipeCompleteCallback? swipeCompleteCallback,
  17. CardDragUpdateCallback? swipeUpdateCallback,
})

Constructor requires Card Widget Builder cardBuilder and your card count totalNum option includes: stack orientation orientation, number of card display in same time stackNum, swipeEdge is the edge to determine action(recover or swipe) when you release your swiping card it is the value of alignment, 0.0 means middle, so it need bigger than zero. and size control params;

Implementation

TinderSwapCard({
  required CardBuilder cardBuilder,
  required int totalNum,
  AmassOrientation orientation = AmassOrientation.bottom,
  int stackNum = 3,
  int animDuration = 800,
  double swipeEdge = 3.0,
  double swipeEdgeVertical = 8.0,
  bool swipeUp = false,
  bool swipeDown = false,
  double? maxWidth,
  double? maxHeight,
  double? minWidth,
  double? minHeight,
  bool allowVerticalMovement = true,
  this.cardController,
  this.swipeCompleteCallback,
  this.swipeUpdateCallback,
})  : assert(stackNum > 1),
      assert(swipeEdge > 0),
      assert(swipeEdgeVertical > 0),
      assert(maxWidth! > minWidth! && maxHeight! > minHeight!),
      _cardBuilder = cardBuilder,
      _totalNum = totalNum,
      _stackNum = stackNum,
      _animDuration = animDuration,
      _swipeEdge = swipeEdge,
      _swipeEdgeVertical = swipeEdgeVertical,
      _swipeUp = swipeUp,
      _swipeDown = swipeDown,
      _allowVerticalMovement = allowVerticalMovement {
  final widthGap = maxWidth! - minWidth!;
  final heightGap = maxHeight! - minHeight!;

  for (var i = 0; i < _stackNum; i++) {
    _cardSizes.add(
      Size(minWidth + (widthGap / _stackNum) * i,
          minHeight + (heightGap / _stackNum) * i),
    );

    switch (orientation) {
      case AmassOrientation.bottom:
        _cardAligns.add(
          Alignment(
            0.0,
            (0.5 / (_stackNum - 1)) * (stackNum - i),
          ),
        );
        break;
      case AmassOrientation.top:
        _cardAligns.add(
          Alignment(
            0.0,
            (-0.5 / (_stackNum - 1)) * (stackNum - i),
          ),
        );
        break;
      case AmassOrientation.left:
        _cardAligns.add(
          Alignment(
            (-0.5 / (_stackNum - 1)) * (stackNum - i),
            0.0,
          ),
        );
        break;
      case AmassOrientation.right:
        _cardAligns.add(
          Alignment(
            (0.5 / (_stackNum - 1)) * (stackNum - i),
            0.0,
          ),
        );
        break;
    }
  }
}