diff --git a/README.md b/README.md index b2030f1..c1c69f4 100644 --- a/README.md +++ b/README.md @@ -84,3 +84,19 @@ void doStuff() { _controller.toggleCard(); } ``` + +You can auto-flip the widget after a certain delay without any external triggering. +```dart +FlipCard( + fill: Fill.fillBack, // Fill the back side of the card to make in the same size as the front. + direction: FlipDirection.HORIZONTAL, // default + side: CardSide.FRONT, // The side to initially display. + front: Container( + child: Text('Front'), + ), + back: Container( + child: Text('Back'), + ), + autoFlipDuration: const Duration(seconds: 2), // The flip effect will work automatically after the 2 seconds +); +``` diff --git a/lib/flip_card.dart b/lib/flip_card.dart index 22942d4..c29827f 100644 --- a/lib/flip_card.dart +++ b/lib/flip_card.dart @@ -61,6 +61,9 @@ class FlipCard extends StatefulWidget { final Fill fill; final CardSide side; + /// If the value is set, the flip effect will work automatically after the specified duration. + final Duration? autoFlipDuration; + /// When enabled, the card will flip automatically when touched. This behavior /// can be disabled if this is not desired. To manually flip a card from your /// code, you could do this: @@ -101,6 +104,7 @@ class FlipCard extends StatefulWidget { this.alignment = Alignment.center, this.fill = Fill.none, this.side = CardSide.FRONT, + this.autoFlipDuration, }) : super(key: key); @override @@ -155,6 +159,10 @@ class FlipCardState extends State ).animate(controller!); widget.controller?.state = this; + + if (widget.autoFlipDuration != null) { + Future.delayed(widget.autoFlipDuration!, toggleCard); + } } @override