HeavenOSK / flutter_swipable_stack

A widget for stacking cards, which users can swipe horizontally and vertically with beautiful animations like Tinder UI.
https://pub.dev/packages/swipable_stack
MIT License
117 stars 48 forks source link

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

Open Jiseeeh opened 7 months ago

Jiseeeh commented 7 months ago

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

bmercan commented 7 months ago

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 commented 7 months ago

Thanks. I'll try it out later