Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized the initState for AnimatedTextKit #169

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/src/animated_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>

int _currentRepeatCount = 0;

int _index = -1;
int _index = 0;

bool _isCurrentlyPausing = false;

Expand All @@ -159,7 +159,7 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>
@override
void initState() {
super.initState();
_nextAnimation();
_initAnimation();
}

@override
Expand All @@ -172,7 +172,6 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>

@override
Widget build(BuildContext context) {
assert(_index >= 0);
final animatedText = widget.animatedTexts[_index];
final completeText = animatedText.completeText();
return GestureDetector(
Expand All @@ -197,9 +196,7 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>
_isCurrentlyPausing = false;

// Handling onNext callback
if (_index > -1) {
widget.onNext?.call(_index, isLast);
}
widget.onNext?.call(_index, isLast);

if (isLast) {
if (widget.isRepeatingAnimation &&
Expand All @@ -219,9 +216,14 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>

if (mounted) setState(() {});

final animatedText = widget.animatedTexts[_index];
_controller.dispose();

_controller?.dispose();
// Re-initialize animation
_initAnimation();
}

void _initAnimation() {
final animatedText = widget.animatedTexts[_index];

_controller = AnimationController(
duration: animatedText.duration,
Expand Down