I’m developing an app with Flutter using the FlipCard package.
I have a grid with 12 FlipCards, I need to select two covered cards, flip them to show what’s behind, perform some checks, and If the checks do not pass, I need to flip back both cards and until the flip animation is completed I shouldn’t be able to click to reveal other cards (this is to avoid introducing bugs).
one of my attempts was this:
myFunction() {
// my stuff
_cardControllers[pickedCards[0]].toggleCard();
_cardControllers[pickedCards[1]].toggleCard();
setState(() {
isFront[pickedCards[0]] = false;
isFront[pickedCards[1]] = false;
});
}
Doing this the toggle is executed only for the first card.
To solve this problem, I tried using a 500-millisecond timer for the second toggle, and this solved the problem. However, there are often bugs that show a card as flipped but with a false value, so the code recognizes it as a covered card. I hypothesise that this is due to various delays caused by animations and Timers present in the code, causing slowdowns and not executing correctly what it should, but this is just my assumption.
I also made some attempts using Flutter’s AnimationController, but I’m not very skilled with animations and wasn’t able to achieve anything.
Is there a way to solve this problem? I am also willing to not use the FlipCard package, as long as I can manage flipping multiple cards simultaneously.
Thank you all.
Giovanni Caciuppo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.