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

How to add more cards underneath existing cards dynamically? #37

Open
topex-psy opened this issue Apr 20, 2024 · 3 comments
Open

How to add more cards underneath existing cards dynamically? #37

topex-psy opened this issue Apr 20, 2024 · 3 comments

Comments

@topex-psy
Copy link

This is my need:
After swiping, when there are only 5 cards left, I need to insert/append more cards

How to achieve this?

@AnupKumarPanwar
Copy link
Owner

As of swipe_cards: ^2.0.0+1, there is no direct method to handle this. But you can achieve this with the following approach.

Check addNewCards(); // Add this line on the 5th last card you add.

_swipeItems.add(SwipeItem(
          content: Content(text: _names[i], color: _colors[i]),
          likeAction: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Liked ${_names[i]}"),
              duration: Duration(milliseconds: 500),
            ));
            addNewCards();  // Add this line on the 5th last card you add.
          },
          nopeAction: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Nope ${_names[i]}"),
              duration: Duration(milliseconds: 500),
            ));
            addNewCards();  // Add this line on the 5th last card you add.
          },
          superlikeAction: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Superliked ${_names[i]}"),
              duration: Duration(milliseconds: 500),
            ));
            addNewCards();  // Add this line on the 5th last card you add.
          },
          onSlideUpdate: (SlideRegion? region) async {
            print("Region $region");
          }));

@topex-psy
Copy link
Author

As of swipe_cards: ^2.0.0+1, there is no direct method to handle this. But you can achieve this with the following approach.

Check addNewCards(); // Add this line on the 5th last card you add.

_swipeItems.add(SwipeItem(
          content: Content(text: _names[i], color: _colors[i]),
          likeAction: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Liked ${_names[i]}"),
              duration: Duration(milliseconds: 500),
            ));
            addNewCards();  // Add this line on the 5th last card you add.
          },
          nopeAction: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Nope ${_names[i]}"),
              duration: Duration(milliseconds: 500),
            ));
            addNewCards();  // Add this line on the 5th last card you add.
          },
          superlikeAction: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              content: Text("Superliked ${_names[i]}"),
              duration: Duration(milliseconds: 500),
            ));
            addNewCards();  // Add this line on the 5th last card you add.
          },
          onSlideUpdate: (SlideRegion? region) async {
            print("Region $region");
          }));

Thank you.
But what does the addNewCards() function looks like?
Is it just adding new items to _swipeItems list variable?
Should we recreate the MatchEngine?

Can you give more complete example?

@AnupKumarPanwar
Copy link
Owner

You can just add new items to _swipeItems and call setState()

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