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

Added request to the init next animation #281

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ List<AnimatedTextExample> 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!!'),
Expand Down
15 changes: 12 additions & 3 deletions lib/src/animated_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -120,6 +126,7 @@ class AnimatedTextKit extends StatefulWidget {
this.onTap,
this.onNext,
this.onNextBeforePause,
this.onRequestNext,
this.onFinished,
this.isRepeatingAnimation = true,
this.totalRepeatCount = 3,
Expand Down Expand Up @@ -181,6 +188,7 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>

void _nextAnimation() {
final isLast = _isLast;
final continueAnimation = widget.onRequestNext?.call(_index, _isLast);

_isCurrentlyPausing = false;

Expand All @@ -205,10 +213,11 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>

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

_controller.dispose();

// Re-initialize animation
_initAnimation();
if (continueAnimation ?? true) {
_controller.dispose();
_initAnimation();
}
}

void _initAnimation() {
Expand Down