toggleCard method

Future<void> toggleCard()

Implementation

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

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

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