appinioGmbH / flutter_packages

Dart and Flutter plugins/packages used and maintained by @appinioGmbH
187 stars 214 forks source link

[ BUG ] : Swiper renders the topmost background card for all background positions #215

Closed BobDickinson closed 5 months ago

BobDickinson commented 9 months ago

Plugin name Appinio Swiper etc.

Describe the bug In the Swiper Example app I added logging to the IndexedWidgetBuilder in the main AppInioSwiper widget and noticed that widget was creating the foreground card, and then creating only the topmost background card for each of the background cards visible in the stack.

The code change was just:

              cardBuilder: (BuildContext context, int index) {
                print("Building card $index");
                return ExampleCard(candidate: candidates[index]);
              },

And the output was a series of:

flutter: Building card 2 (4) flutter: Building card 3

This seemed to indicate that instead of creating background cards 3, 4, 5, and 6 as expected, it created background card 3 four times.

To verify this, I modified the example card widget to show only the background color so you could tell them apart in the background stack, and I verified that for any given state, all of the background cards are the same (they are the same color as to topmost background card, until you swipe, then they all change to the color of the new topmost background card).

If the visible part of the card is different between cards, this is a pretty nasty bug.

To Reproduce Steps to reproduce the behavior:

  1. Modify the Example app so that the card is only the background color
  2. Run the sample app and observe the behavior of the background cards as you swipe

Expected behavior Each background card rendered should have the correct index and be the correct card.

Screenshot 2023-12-18 at 9 24 16 AM

BobDickinson commented 9 months ago

I think the issue is in the background generator function:

        indices: List.generate(
          effectiveBackgroundCardCount,
          (index) => (foregroundIndex + 1) % widget.cardCount,
        ),

That should be:

        indices: List.generate(
          effectiveBackgroundCardCount,
          (index) => (foregroundIndex + 1 + index) % widget.cardCount,
        ),

I think (I'm very new to Flutter/Dart).