jushutch / swiping_card_deck

A widget for swiping through a deck of cards with gestures or buttons.
https://pub.dev/packages/swiping_card_deck
BSD 3-Clause "New" or "Revised" License
13 stars 10 forks source link

Add parameters to onSwipe callbacks #26

Closed jushutch closed 2 years ago

jushutch commented 2 years ago

Added two parameters to the onLeftSwipe and onRightSwipe callback functions: cardDeck and cardsSwiped. The purpose of the first parameter is to allow users of the package to modify the deck during the callback. One potential use case is described in issue #23, where a user wants to add new cards to the end of the deck dynamically. The second parameter allows users to access the number of cards swiped so far in this deck. This can be useful for determining the current index in the deck, as requested in issue #20. Here is a basic example of using both parameters:

onLeftSwipe: (Card card, List<Card> cardDeck, int cardsSwiped) {
  // insert a new card into the back of the deck
  cardDeck.insert(0, const Card(
              color: Colors.black, child: SizedBox(height: 300, width: 200)),
  );

  // print the number of cards that have been swiped
  debugPrint("Number of cards swiped: $cardsSwiped");
}

Since this is a breaking change, it will first be part of pre-release v2.0.0-dev.0.

Resolves #20 Resolves #23