From dffdcfbdb675b2dbef3468226773e937b150a4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20Ayd=C4=B1n?= Date: Fri, 8 Apr 2022 21:21:35 +0300 Subject: [PATCH 1/4] Added autoFlipDuration parameter --- lib/flip_card.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/flip_card.dart b/lib/flip_card.dart index 58b9a44..ae9ebe5 100644 --- a/lib/flip_card.dart +++ b/lib/flip_card.dart @@ -60,6 +60,7 @@ class FlipCard extends StatefulWidget { final FlipCardController? controller; final Fill fill; final CardSide side; + 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 @@ -101,6 +102,7 @@ class FlipCard extends StatefulWidget { this.alignment = Alignment.center, this.fill = Fill.none, this.side = CardSide.FRONT, + this.autoFlipDuration = const Duration(seconds: 1000), }) : super(key: key); @override @@ -155,6 +157,10 @@ class FlipCardState extends State ).animate(controller!); widget.controller?.state = this; + + if (widget.autoFlipDuration != null) { + Future.delayed(widget.autoFlipDuration!, () => toggleCard()); + } } /// Flip the card From 2ca876adef1472852be72512911239fe81eca20f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20Ayd=C4=B1n?= Date: Fri, 8 Apr 2022 21:30:44 +0300 Subject: [PATCH 2/4] Removed default autoFlipDuration --- lib/flip_card.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/flip_card.dart b/lib/flip_card.dart index ae9ebe5..811e16a 100644 --- a/lib/flip_card.dart +++ b/lib/flip_card.dart @@ -102,7 +102,7 @@ class FlipCard extends StatefulWidget { this.alignment = Alignment.center, this.fill = Fill.none, this.side = CardSide.FRONT, - this.autoFlipDuration = const Duration(seconds: 1000), + this.autoFlipDuration, }) : super(key: key); @override From fb773fdf7263ad40e9592d23427358a8a4c6e0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20Ayd=C4=B1n?= Date: Fri, 2 Dec 2022 21:41:01 +0300 Subject: [PATCH 3/4] Added documentation --- README.md | 16 ++++++++++++++++ lib/flip_card.dart | 2 ++ 2 files changed, 18 insertions(+) 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 d74f6e0..f51eb11 100644 --- a/lib/flip_card.dart +++ b/lib/flip_card.dart @@ -60,6 +60,8 @@ class FlipCard extends StatefulWidget { final FlipCardController? controller; 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 From f5010a39d26b4c4ef4684dc2806a75c888dd7685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20Ayd=C4=B1n?= Date: Fri, 2 Dec 2022 21:44:26 +0300 Subject: [PATCH 4/4] Applied tear-off --- lib/flip_card.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/flip_card.dart b/lib/flip_card.dart index f51eb11..c29827f 100644 --- a/lib/flip_card.dart +++ b/lib/flip_card.dart @@ -161,7 +161,7 @@ class FlipCardState extends State widget.controller?.state = this; if (widget.autoFlipDuration != null) { - Future.delayed(widget.autoFlipDuration!, () => toggleCard()); + Future.delayed(widget.autoFlipDuration!, toggleCard); } }