Skip to content

Commit

Permalink
add startIndex for animatedText
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezat66 committed Oct 18, 2021
1 parent 24c2592 commit f50511f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
21 changes: 21 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ List<AnimatedTextExample> 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],
Expand Down
7 changes: 5 additions & 2 deletions lib/src/animated_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ class AnimatedTextKit extends StatefulWidget {
///
/// By default it is set to 3
final int totalRepeatCount;

final int startIndex;
const AnimatedTextKit({
Key? key,
required this.animatedTexts,
this.pause = const Duration(milliseconds: 1000),
this.displayFullTextOnTap = false,
this.stopPauseOnTap = false,
this.onTap,
this.startIndex = 0,
this.onNext,
this.onNextBeforePause,
this.onFinished,
Expand Down Expand Up @@ -150,6 +151,7 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>

@override
void initState() {
_index = widget.startIndex< widget.animatedTexts.length?widget.startIndex:0;
super.initState();
_initAnimation();
}
Expand Down Expand Up @@ -212,8 +214,9 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>
}

void _initAnimation() {

_currentAnimatedText = widget.animatedTexts[_index];

_controller = AnimationController(
duration: _currentAnimatedText.duration,
vsync: this,
Expand Down

0 comments on commit f50511f

Please sign in to comment.