flutter_swipable_stack icon indicating copy to clipboard operation
flutter_swipable_stack copied to clipboard

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

Open stackovermaw opened this issue 1 year ago • 5 comments

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

stackovermaw avatar Mar 24 '24 09:03 stackovermaw

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);
                }
              },
             
            ),

bmercan avatar Apr 06 '24 16:04 bmercan

Thanks. I'll try it out later

stackovermaw avatar Apr 07 '24 05:04 stackovermaw