From 52686d8d64a9160cd56d9f542f1073f27c2e4002 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 11 Mar 2022 14:24:59 -0300 Subject: [PATCH 1/2] add request next animation function --- lib/src/animated_text.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/src/animated_text.dart b/lib/src/animated_text.dart index db3f851..4b10ae1 100644 --- a/lib/src/animated_text.dart +++ b/lib/src/animated_text.dart @@ -95,6 +95,12 @@ class AnimatedTextKit extends StatefulWidget { /// Will be called at the end of n-1 animation, before the pause parameter final void Function(int, bool)? onNextBeforePause; + /// Adds the onRequestNextAnimation request the next to the animated widget + /// + /// Will be called right before the next text. It will only call the next animation if the return is true. + /// If the return is false, the animation will stop. + final bool Function(int, bool)? onRequestNext; + /// Set if the animation should not repeat by changing the value of it to false. /// /// By default it is set to true. @@ -120,6 +126,7 @@ class AnimatedTextKit extends StatefulWidget { this.onTap, this.onNext, this.onNextBeforePause, + this.onRequestNext, this.onFinished, this.isRepeatingAnimation = true, this.totalRepeatCount = 3, @@ -181,6 +188,7 @@ class _AnimatedTextKitState extends State void _nextAnimation() { final isLast = _isLast; + final continueAnimation = widget.onRequestNext?.call(_index, _isLast); _isCurrentlyPausing = false; @@ -205,10 +213,11 @@ class _AnimatedTextKitState extends State if (mounted) setState(() {}); - _controller.dispose(); - // Re-initialize animation - _initAnimation(); + if (continueAnimation ?? true) { + _controller.dispose(); + _initAnimation(); + } } void _initAnimation() { From e94d211ce9712160fe30fa3b5429ddcb004563c6 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Fri, 11 Mar 2022 14:34:50 -0300 Subject: [PATCH 2/2] Added onRequestNext --- example/lib/main.dart | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/example/lib/main.dart b/example/lib/main.dart index c5c618b..3db5a27 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -178,6 +178,14 @@ List animatedTextExamples({VoidCallback? onTap}) => fontWeight: FontWeight.bold, ), child: AnimatedTextKit( + onRequestNext: (index, isLast) { + // any condition + if(1 > 0){ + return true; + }else{ + return false; + } + }, animatedTexts: [ FadeAnimatedText('do IT!'), FadeAnimatedText('do it RIGHT!!'),