From f50511f554b35e30e912444dba28343fa781e902 Mon Sep 17 00:00:00 2001 From: alireza taghizadeh Date: Mon, 18 Oct 2021 12:27:46 +0300 Subject: [PATCH] add startIndex for animatedText --- example/lib/main.dart | 21 +++++++++++++++++++++ lib/src/animated_text.dart | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index c5c618b..f135605 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -187,6 +187,27 @@ List animatedTextExamples({VoidCallback? onTap}) => ), ), ), + + AnimatedTextExample( + label: 'Fade With Index', + color: Colors.brown[600], + + child: DefaultTextStyle( + style: const TextStyle( + fontSize: 32.0, + fontWeight: FontWeight.bold, + ), + child: AnimatedTextKit( + startIndex: 1, + animatedTexts: [ + FadeAnimatedText('do IT!'), + FadeAnimatedText('do it RIGHT!!'), + FadeAnimatedText('do it RIGHT NOW!!!'), + ], + onTap: onTap, + ), + ), + ), AnimatedTextExample( label: 'Typer', color: Colors.lightGreen[800], diff --git a/lib/src/animated_text.dart b/lib/src/animated_text.dart index db3f851..b6c2f4b 100644 --- a/lib/src/animated_text.dart +++ b/lib/src/animated_text.dart @@ -110,7 +110,7 @@ class AnimatedTextKit extends StatefulWidget { /// /// By default it is set to 3 final int totalRepeatCount; - + final int startIndex; const AnimatedTextKit({ Key? key, required this.animatedTexts, @@ -118,6 +118,7 @@ class AnimatedTextKit extends StatefulWidget { this.displayFullTextOnTap = false, this.stopPauseOnTap = false, this.onTap, + this.startIndex = 0, this.onNext, this.onNextBeforePause, this.onFinished, @@ -150,6 +151,7 @@ class _AnimatedTextKitState extends State @override void initState() { + _index = widget.startIndex< widget.animatedTexts.length?widget.startIndex:0; super.initState(); _initAnimation(); } @@ -212,8 +214,9 @@ class _AnimatedTextKitState extends State } void _initAnimation() { + _currentAnimatedText = widget.animatedTexts[_index]; - + _controller = AnimationController( duration: _currentAnimatedText.duration, vsync: this,