Skip to content

Commit

Permalink
feat: add repeat forever option (#72)
Browse files Browse the repository at this point in the history
* add ability to repeat forever for typewriter

* feat: Add repeatForever option
  • Loading branch information
yiminghan authored May 17, 2020
1 parent bde1cc4 commit 72229de
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.1.0
Add `repeatForever` option.

## 2.0.1
* Minor updates.

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Add this to your package's `pubspec.yaml` file:

```yaml
dependencies:
animated_text_kit: ^2.0.1
animated_text_kit: ^2.1.0
```
### 2. Install it
Expand Down Expand Up @@ -84,11 +84,12 @@ import 'package:animated_text_kit/animated_text_kit.dart';

# Usage

You can override the `duration` of animation of single text by setting its duration in each AnimatedTextKit class, also you can set the time of the pause between texts by setting the `pause` parameter and with this when `isRepeatingAnimation` is set to true, you can set number of times the animation should repeat with `totalRepeatCount`. The `speed` parameter is also included for some classes which sets the delay between the apparition of each characters. Also, the `displayFullTextOnTap` and `stopPauseOnTap` parameters have been included for some classes.
You can override the `duration` of animation of single text by setting its duration in each AnimatedTextKit class, also you can set the time of the pause between texts by setting the `pause` parameter and with this when `isRepeatingAnimation` is set to true, you can set number of times the animation should repeat with `totalRepeatCount` (or repeat forever with `repeatForever`). The `speed` parameter is also included for some classes which sets the delay between the apparition of each characters. Also, the `displayFullTextOnTap` and `stopPauseOnTap` parameters have been included for some classes.
```dart
TypewriterAnimatedTextKit(
duration: Duration(milliseconds: 2000),
totalRepeatCount: 4,
repeatForever: true, //this will ignore [totalRepeatCount]
pause: Duration(milliseconds: 1000),
text: ["do IT!", "do it RIGHT!!", "do it RIGHT NOW!!!"],
textStyle: TextStyle(fontSize: 32.0, fontWeight: FontWeight.bold),
Expand Down
14 changes: 12 additions & 2 deletions lib/src/colorize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class ColorizeAnimatedTextKit extends StatefulWidget {
/// By default it is set to true.
final bool isRepeatingAnimation;

/// Sets if the animation should repeat forever. [isRepeatingAnimation] also
/// needs to be set to true if you want to repeat forever.
///
/// By default it is set to false, if set to true, [totalRepeatCount] is ignored.
final bool repeatForever;

/// Sets the number of times animation should repeat
///
/// By default it is set to 3
Expand All @@ -75,6 +81,7 @@ class ColorizeAnimatedTextKit extends StatefulWidget {
this.alignment = AlignmentDirectional.topStart,
this.textAlign = TextAlign.start,
this.totalRepeatCount = 3,
this.repeatForever = false,
this.isRepeatingAnimation = true})
: super(key: key);

Expand Down Expand Up @@ -183,9 +190,12 @@ class _RotatingTextState extends State<ColorizeAnimatedTextKit>

if (isLast) {
if (widget.isRepeatingAnimation &&
(_currentRepeatCount != (widget.totalRepeatCount - 1))) {
(widget.repeatForever ||
_currentRepeatCount != (widget.totalRepeatCount - 1))) {
_index = 0;
_currentRepeatCount++;
if (!widget.repeatForever) {
_currentRepeatCount++;
}
} else {
if (widget.onFinished != null) widget.onFinished();
return;
Expand Down
14 changes: 12 additions & 2 deletions lib/src/fade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class FadeAnimatedTextKit extends StatefulWidget {
/// By default it is set to 3
final int totalRepeatCount;

/// Sets if the animation should repeat forever. [isRepeatingAnimation] also
/// needs to be set to true if you want to repeat forever.
///
/// By default it is set to false, if set to true, [totalRepeatCount] is ignored.
final bool repeatForever;

/// Set if the animation should not repeat by changing the value of it to false.
///
/// By default it is set to true.
Expand Down Expand Up @@ -84,6 +90,7 @@ class FadeAnimatedTextKit extends StatefulWidget {
this.totalRepeatCount = 3,
this.alignment = AlignmentDirectional.topStart,
this.textAlign = TextAlign.start,
this.repeatForever = false,
this.isRepeatingAnimation = true})
: super(key: key);

Expand Down Expand Up @@ -193,9 +200,12 @@ class _RotatingTextState extends State<FadeAnimatedTextKit>

if (isLast) {
if (widget.isRepeatingAnimation &&
(_currentRepeatCount != (widget.totalRepeatCount - 1))) {
(widget.repeatForever ||
_currentRepeatCount != (widget.totalRepeatCount - 1))) {
_index = 0;
_currentRepeatCount++;
if (!widget.repeatForever) {
_currentRepeatCount++;
}
} else {
if (widget.onFinished != null) widget.onFinished();
return;
Expand Down
14 changes: 12 additions & 2 deletions lib/src/rotate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class RotateAnimatedTextKit extends StatefulWidget {
/// By default it is set to 3
final int totalRepeatCount;

/// Sets if the animation should repeat forever. [isRepeatingAnimation] also
/// needs to be set to true if you want to repeat forever.
///
/// By default it is set to false, if set to true, [totalRepeatCount] is ignored.
final bool repeatForever;

/// Set if the animation should not repeat by changing the value of it to false.
///
/// By default it is set to true.
Expand All @@ -83,6 +89,7 @@ class RotateAnimatedTextKit extends StatefulWidget {
this.alignment = const Alignment(0.0, 0.0),
this.textAlign = TextAlign.start,
this.displayFullTextOnTap = false,
this.repeatForever = false,
this.isRepeatingAnimation = true})
: super(key: key);

Expand Down Expand Up @@ -201,9 +208,12 @@ class _RotatingTextState extends State<RotateAnimatedTextKit>

if (isLast) {
if (widget.isRepeatingAnimation &&
(_currentRepeatCount != (widget.totalRepeatCount - 1))) {
(widget.repeatForever ||
_currentRepeatCount != (widget.totalRepeatCount - 1))) {
_index = 0;
_currentRepeatCount++;
if (!widget.repeatForever) {
_currentRepeatCount++;
}
} else {
if (widget.onFinished != null) widget.onFinished();
return;
Expand Down
14 changes: 12 additions & 2 deletions lib/src/scale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class ScaleAnimatedTextKit extends StatefulWidget {
/// By default it is set to 3
final int totalRepeatCount;

/// Sets if the animation should repeat forever. [isRepeatingAnimation] also
/// needs to be set to true if you want to repeat forever.
///
/// By default it is set to false, if set to true, [totalRepeatCount] is ignored.
final bool repeatForever;

/// Set if the animation should not repeat by changing the value of it to false.
///
/// By default it is set to true.
Expand Down Expand Up @@ -88,6 +94,7 @@ class ScaleAnimatedTextKit extends StatefulWidget {
this.totalRepeatCount = 3,
this.alignment = AlignmentDirectional.topStart,
this.textAlign = TextAlign.start,
this.repeatForever = false,
this.isRepeatingAnimation = true,
this.displayFullTextOnTap = false,
this.stopPauseOnTap = false})
Expand Down Expand Up @@ -204,9 +211,12 @@ class _RotatingTextState extends State<ScaleAnimatedTextKit>

if (isLast) {
if (widget.isRepeatingAnimation &&
(_currentRepeatCount != (widget.totalRepeatCount - 1))) {
(widget.repeatForever ||
_currentRepeatCount != (widget.totalRepeatCount - 1))) {
_index = 0;
_currentRepeatCount++;
if (!widget.repeatForever) {
_currentRepeatCount++;
}
} else {
if (widget.onFinished != null) widget.onFinished();
return;
Expand Down
14 changes: 12 additions & 2 deletions lib/src/typewriter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class TypewriterAnimatedTextKit extends StatefulWidget {
/// By default it is set to 3
final int totalRepeatCount;

/// Sets if the animation should repeat forever. [isRepeatingAnimation] also
/// needs to be set to true if you want to repeat forever.
///
/// By default it is set to false, if set to true, [totalRepeatCount] is ignored.
final bool repeatForever;

/// Set if the animation should not repeat by changing the value of it to false.
///
/// By default it is set to true.
Expand Down Expand Up @@ -82,6 +88,7 @@ class TypewriterAnimatedTextKit extends StatefulWidget {
this.totalRepeatCount = 3,
this.alignment = AlignmentDirectional.topStart,
this.textAlign = TextAlign.start,
this.repeatForever = false,
this.isRepeatingAnimation = true})
: assert(!(text == null), 'You should specify the list of text'),
super(key: key);
Expand Down Expand Up @@ -208,9 +215,12 @@ class _TypewriterState extends State<TypewriterAnimatedTextKit>

if (isLast) {
if (widget.isRepeatingAnimation &&
(_currentRepeatCount != (widget.totalRepeatCount - 1))) {
(widget.repeatForever ||
_currentRepeatCount != (widget.totalRepeatCount - 1))) {
_index = 0;
_currentRepeatCount++;
if (!widget.repeatForever) {
_currentRepeatCount++;
}
} else {
if (widget.onFinished != null) widget.onFinished();
return;
Expand Down

0 comments on commit 72229de

Please sign in to comment.