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

Swipeable stack is not working when you call setState inside onSwipeCompleted or onWillMoveNext #80

Open
Jiseeeh opened this issue Mar 24, 2024 · 2 comments

Comments

@Jiseeeh
Copy link

Jiseeeh commented Mar 24, 2024

When I call setState inside those callbacks, the next time you swipe won't work.

@bmercan
Copy link

bmercan commented Apr 6, 2024

I found a solution for that, i added a ValueNotifier for index, then listen SwipeableStack current index from ValueNotifier then call setstate from there.

  ValueNotifier<int> pageIndex = ValueNotifier<int>(0);


  @override
  void initState() {
    super.initState();
    pageIndex.addListener(() {
      int leftCards = cards.length - pageIndex.value;
      if (leftCards < 5) {
        print('fetching moooooreeee');
        fetchMore();
        setState(() {});
      }
    });
  }
  
  
    SwipableStack(
              onSwipeCompleted: (index, direction) {
                pageIndex.value = index;

                if (direction == SwipeDirection.right) {
                  //handleInteraction(index, false);
                } else {
                  likeCountLeft--;
                  //handleInteraction(index, true);
                }
              },
             
            ),

@Jiseeeh
Copy link
Author

Jiseeeh commented Apr 7, 2024

Thanks. I'll try it out later

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