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

An option to show animated texts without overriding it #300

Open
wants to merge 5 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ It has many configurable properties, including:
- `isRepeatingAnimation` – controls whether the animation repeats
- `repeatForever` – controls whether the animation repeats forever
- `totalRepeatCount` – number of times the animation should repeat (when `repeatForever` is `false`)
- `overrideTexts` – it allows to show animated texts without override it (default is `true`)

There are also custom callbacks:

Expand Down
32 changes: 25 additions & 7 deletions lib/src/animated_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class AnimatedTextKit extends StatefulWidget {
/// By default it is set to false.
final bool displayFullTextOnTap;

///Overrides previous text to other one. It's true by default
final bool overrideTexts;

/// If on pause, should a tap remove the remaining pause time ?
///
/// By default it is set to false.
Expand Down Expand Up @@ -117,6 +120,7 @@ class AnimatedTextKit extends StatefulWidget {
this.pause = const Duration(milliseconds: 1000),
this.displayFullTextOnTap = false,
this.stopPauseOnTap = false,
this.overrideTexts = true,
this.onTap,
this.onNext,
this.onNextBeforePause,
Expand Down Expand Up @@ -163,22 +167,36 @@ class _AnimatedTextKitState extends State<AnimatedTextKit>

@override
Widget build(BuildContext context) {
final completeText = _currentAnimatedText.completeText(context);
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: _onTap,
child: _isCurrentlyPausing || !_controller.isAnimating
? completeText
: AnimatedBuilder(
animation: _controller,
builder: _currentAnimatedText.animatedBuilder,
child: completeText,
child: widget.overrideTexts
? _animationRenderer()
: Column(
children: widget.animatedTexts
.take(_index)
.map<Widget>((e) => Text(
e.text,
style: e.textStyle,
))
.toList() +
[_animationRenderer()],
),
);
}

bool get _isLast => _index == widget.animatedTexts.length - 1;

Widget _animationRenderer() {
final completeText = _currentAnimatedText.completeText(context);
return _isCurrentlyPausing || !_controller.isAnimating
? completeText
: AnimatedBuilder(
animation: _controller,
builder: _currentAnimatedText.animatedBuilder,
child: completeText);
}

void _nextAnimation() {
final isLast = _isLast;

Expand Down