toggleCard method

Future<void> toggleCard()

Flip the card If awaited, returns after animation completes.

Implementation

Future<void> toggleCard() async {
  widget.onFlip?.call();

  final isFrontBefore = isFront;
  controller!.duration = Duration(milliseconds: widget.speed);

  final animation = isFront ? controller!.forward() : controller!.reverse();
  animation.whenComplete(() {
    if (widget.onFlipDone != null) widget.onFlipDone!(isFront);
    if (!mounted) return;
    setState(() => isFront = !isFrontBefore);
  });
}