Skip to content

dannaka/flutter_swipable_stack

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

swipable_stack

A widget for stacking cards, which users can swipe horizontally and vertically with beautiful animations.

(Sorry, the package name swipable_stack is typo of swipeable stack)

Usage

builder

A SwipeableStack uses a builder to display widgets.

SwipeableStack(
  builder: (context, index, constraints) {
    return Image.asset(imagePath);
  },
),

onSwipeCompleted

You can get completion event with onSwipeCompleted.

SwipeableStack(
  onSwipeCompleted: (index, direction) {
    print('$index, $direction');
  },
)

overlayBuilder

You can show overlay on the front card with overlayBuilder.

SwipeableStack(
  overlayBuilder: (
    context,
    constraints,
    index,
    direction,
    swipeProgress,
  ) {
    final opacity = min(swipeProgress, 1.0);
    final isRight = direction == SwipeDirection.right;
    return Opacity(
      opacity: isRight ? opacity : 0,
      child: CardLabel.right(),
    );
  },
)

controller

SwipeableStackController allows you to control swipe action & also rewind recent action.

final controller = SwipeableStackController();

SwipeableStack(
  controller:controller,
  builder: (context, index, constraints) {
    return Image.asset(imagePath);
  },
);
controller.next(
  swipeDirection: SwipeDirection.right,
);
controller.rewind();

SwipeableStackController provides to access currentIndex of SwipeableStack.

final controller = SwipeableStackController();
controller.addListener(() {
  print('${_controller.currentIndex}');
});

onWillMoveNext

You can also restrict user actions according to index or action with onWillMoveNext.

SwipeableStack(
  onWillMoveNext: (index, direction) {
    final allowedActions = [
      SwipeDirection.right,
      SwipeDirection.left,
    ];
    return allowedActions.contains(direction);
  },
);

About

A widget for stacking cards, which users can swipe horizontally and vertically with beautiful animations like Tinder UI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Dart 98.6%
  • Other 1.4%