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

Adding more cards on reverse swipe jumps to last index #96

Open
lhengl opened this issue Dec 14, 2023 · 2 comments
Open

Adding more cards on reverse swipe jumps to last index #96

lhengl opened this issue Dec 14, 2023 · 2 comments

Comments

@lhengl
Copy link

lhengl commented Dec 14, 2023

When working with dynamic list of cards (eg. fetching more cards from a datasource), adding cards while swiping in the forward direction works as expected. However, if loop is enabled, adding more cards while reverse swiping will cause the index to jump to the last index.

Suppose we have the following:

  final cards = ['card0', 'card1', 'card2'];

  // ...

  onIndexChanged: (index) async {
            if (index == cards.length - 1) {
              setState(() {
                cards.add('card[${cards.length}]');
              });
            }
          },

In the above code:

  1. if you swipe in the forward direction card0 > card1 > card2
  2. a new card3 is added
  3. the view shows card2
  4. when you swipe to card3
  5. a new card4 is added
  6. the view shows card3
  7. ...and so on.

However:

  1. if you swipe card0 > card2 (in the reverse)
  2. a new card3 will be added
  3. the view shows card3

The expectation is that the view should show card2, because the swipe action takes the user to card2 first, then it adds card3 at the end of the list.

Once this bug is triggered, the forward direction swipe will also bug out. Meaning:

  1. if you reverse swipe card0 > card2 to trigger the bug
  2. the view will be on card3
  3. now swipe in the forward direction card3 > card0 > card1 > card2 > card3
  4. a new card4 will be added
  5. the view will also show card4 immediately
  6. meaning that card3 was skipped entirely

Imagine you're fetching 10 items at a time, that means that if this bug is triggered, 10 items will be skipped, and swiping back will see 10 new items before the user reaches the item they were on previously.

I've forked the repo to try and figure out the problem with an example, but I can't figure this out. Looking for someone with more experience with the package to help fix this bug. In the fork, you can run the example app and choose the last "Dynamic list" to option see the bug in action:

https://github.com/lhengl/card_swiper

@CodibexAman
Copy link

Hi. Did you get a fix for this?

@lhengl
Copy link
Author

lhengl commented Apr 17, 2024

Hi. Did you get a fix for this?

Hi,

I just disable loop... it didn't make sense to have a loop while fetching new data anyway... I would only use loop if the of items are known in advance.

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