Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnSwipe always showing the Next Card #32

Open
sanjibnarzary opened this issue Feb 21, 2024 · 1 comment
Open

OnSwipe always showing the Next Card #32

sanjibnarzary opened this issue Feb 21, 2024 · 1 comment

Comments

@sanjibnarzary
Copy link

sanjibnarzary commented Feb 21, 2024

Is it possible to show the previous Card on SwipeDown or Swipe left. The example application is always showing the next Card on whatever direction you swipe. The undo button works as expected but I can not do it on swipe.

I tried this way

bool _onSwipe(
    int previousIndex,
    int? currentIndex,
    CardSwiperDirection direction,
  ) {
    if (direction.name == 'left') {
      debugPrint(
          'The card $previousIndex was swiped to the ${direction.name}. Now the card $currentIndex is on top');
    } else if (direction.name == 'right') {
      debugPrint(
          'The card $previousIndex was swiped to the ${direction.name}. Now the card $currentIndex is on top');
    } else if (direction.name == 'top') {
      debugPrint(
          'The card $previousIndex was swiped to the ${direction.name}. Now the card $currentIndex is on top');
    } else if (direction.name == 'bottom') {
      controller.undo();
      bool h = _onUndo(previousIndex - 1, currentIndex!, direction);
      debugPrint(
          '$h The card $previousIndex was swiped to the ${direction.name}. Now the card $currentIndex is on top');
    } else {
      debugPrint(
          'The card $previousIndex was swiped to the ${direction.name}. Now the card $currentIndex is on top');
    }

    return true;
  }
@vtck
Copy link

vtck commented Mar 24, 2024

You can have a custom list of cards, which is updated when _onSwipe and onSwipeDirectionChange occur, even updating its 'direction' by sorting the next card the way you want it. Simply maintain the original collection of your cards and utilize a separate collection for selected elements in your builder, then update that collection after events occur.

You dont need 'Undo' because you can simulate backward swiping by changing next element on the fly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants