ninest / swipeable_card

🂱 [WIP] A Flutter package to implement smooth swipeable playing card like-widgets
https://pub.dev/packages/swipeable_card
BSD 2-Clause "Simplified" License
22 stars 4 forks source link

SwipeableWidget.builder #6

Open SncOne opened 4 years ago

SncOne commented 4 years ago

Is it possible to add this feature

ninest commented 4 years ago

I believe you want it similar to ListView.builder? While it isn't there in the same way, check out the example here: https://github.com/ninest/swipeable_card/blob/v1.x.x/example/lib/example_route.dart

Basically, you have a list of your cards and the current card index. Your current card is shown as a child of SwipeableWidget, and the next card(s) is put into the nextCards parameter. This way, you are only showing the top card and the card behind it. You can, for example, show the next 3 cards if you put something like this as the nextCards parameter:

cards[currentCardIndex + 3],
cards[currentCardIndex + 2],
cards[currentCardIndex + 1]

A more complex example can be found in my Shots app, this file especially.

If you see the demo, you can see the top card and cards behind it. I've put all cards at a random offset and angle. While it looks like you can see the entire deck, you are actually only look at the top card and 3 cards behind it. If you notice, when the top card is swiped, another card is being added the end of the list.