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

TinderSwapCard empty when rebuilding after last swipe #49

Open
fgarciaDev opened this issue Aug 29, 2020 · 4 comments
Open

TinderSwapCard empty when rebuilding after last swipe #49

fgarciaDev opened this issue Aug 29, 2020 · 4 comments

Comments

@fgarciaDev
Copy link

I am using this to present items and don't distinguish between L/R swipes. After swiping thru all items, I rebuild the view, however, the TinderSwapCard widget remains empty. Is there a way to tell the TinderSwapCard to rebuild after last item is swiped? Don't know if this is a bug or enhancement request.

Below is what I am trying to do, but even though I rebuild, TinderSwapCard never updates after the last card is dismissed.

import 'package:my_app/Components/itemRequest.dart';
import 'package:my_app/Screen/Request/requestDetail.dart';
import 'package:my_app/data/Model/item.dart';
import 'package:flutter_tindercard/flutter_tindercard.dart';

class CardsContainer extends StatefulWidget {
  final List<Item> items;

  const CardsContainer({Key key, @required this.items}) : super(key: key);

  @override
  _CardsContainerState createState() => _CardsContainerState();
}


class _CardsContainerState extends State<CardsContainer> {
  TinderSwapCard cards;

  @override
  Widget build(BuildContext context) {
    if (cards == null) {
      cards = buildCards();
    }

    return Container(
      height: 330,
      child: cards,
    );
  }

  TinderSwapCard buildCards() {
    return TinderSwapCard(
      orientation: AmassOrientation.BOTTOM,
      totalNum: widget.items.length,
      stackNum: 5,
      maxWidth: MediaQuery.of(context).size.width,
      minWidth: MediaQuery.of(context).size.width * 0.9,
      maxHeight: MediaQuery.of(context).size.width * 0.9,
      minHeight: MediaQuery.of(context).size.width * 0.85,
      cardBuilder: (context, index) => ItemRequest(
        avatar: widget.items[index].avatar,
        userName: widget.items[index].name,
        date: widget.items[index].date.toString(),
        onTap: (){
          Navigator.of(context).push(MaterialPageRoute(builder: (context) => ItemDetail()));
        },
      ),
      swipeCompleteCallback: (CardSwipeOrientation orientation, int index) {
        // 
        // TRYING TO REBUILD CARD WIDGET TO DISPLAY ALL CARDS AGAIN
        // 
        if (index == widget.items.length-1) {
          setState(() {
            cards = null;
          });
        }
      }
    );
  }
}```
@Loisgenesis
Copy link

@fgarciaDev Please have you been able to resolve this issue, if you have can you paste the solution here thanks.

@dzzzzmodi
Copy link

@fgarciaDev @Loisgenesis
You need to detect the last swipe or 3-4 swipes before the last swipe based on index and total length of your list. Once you got that, you need to append data into the list you are passing in the widget.
Let me know if you need any more help, I have resolved it in my project.

@akreienbring
Copy link

I've got the same problem. I'm quite confused about the question how the cardBuilder is dealing with the index.

Let's say I've got a list of only two items: items[0] and items[1]. When swiping through this list I want to start with a certain index and then, if the end or the beginning of the list is reached 'switch' over to the beginning or the end respectively. Such as (if index > 1 then index = 0 or if index < 0 then index = 1.

I can't get this working :-( But why not? Let me explain...

Reason1: I can not set a starting index. The stack of cards always starts with 0. That's why I can not use buildCard(index) in the cardBuilder. If I want to start with items[myCurrentIndex] this fails. So I start with buildCard(myCurrentIndex) and that works! The correct card is shown.

Reason2: Let's say, when I swipe left, the index should increase and when I swipe right the index should decrease. OK! I can detect the direction of swiping :-) so simply increase / decrease myCurrentIndex dependent on the swipe direction! And when I reach the upper end (2 in the example) I set it to 0 and when I reach the lower end (-1 in the example) I set it to 1. Sounds easy.. BUT: Surprise... Surprise... This only works once :-O After buildCard(myCurrentIndex) the second time the card is empty :-O

This is a really good package. And I took the time to explain a failing simple but everyday usecase to make it possible to enhance it. If I overlooked a feature, please let me know.

@vitulgoyani
Copy link

hello I also have the same problem when I append list with the set state that time it will start with first card

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

5 participants