Skip to content

Commit

Permalink
Merge pull request #123 from awhitford/timer_dispose
Browse files Browse the repository at this point in the history
Bug fix: Properly disposed of Timer for Rotate, Scale, and Typer.
  • Loading branch information
aagarwal1012 committed Oct 12, 2020
2 parents 83a9ffd + 8691283 commit cb43a4d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/src/rotate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class _RotatingTextState extends State<RotateAnimatedTextKit>

@override
void dispose() {
_timer?.cancel();
_controller?.stop();
_controller?.dispose();
super.dispose();
Expand Down Expand Up @@ -268,6 +269,7 @@ class _RotatingTextState extends State<RotateAnimatedTextKit>

void _animationEndCallback(state) {
if (state == AnimationStatus.completed) {
assert(null == _timer || !_timer.isActive);
_timer = Timer(_texts[_index]['pause'], _nextAnimation);
}
}
Expand All @@ -282,6 +284,7 @@ class _RotatingTextState extends State<RotateAnimatedTextKit>

_setPause();

assert(null == _timer || !_timer.isActive);
_timer = Timer(_texts[_index]['pause'], _nextAnimation);
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/scale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class _ScaleTextState extends State<ScaleAnimatedTextKit>

@override
void dispose() {
_timer?.cancel();
_controller?.stop();
_controller?.dispose();
super.dispose();
Expand Down Expand Up @@ -255,6 +256,7 @@ class _ScaleTextState extends State<ScaleAnimatedTextKit>
void _animationEndCallback(state) {
if (state == AnimationStatus.completed) {
_isCurrentlyPausing = true;
assert(null == _timer || !_timer.isActive);
_timer = Timer(_texts[_index]['pause'], _nextAnimation);
}
}
Expand All @@ -274,6 +276,7 @@ class _ScaleTextState extends State<ScaleAnimatedTextKit>

_setPause();

assert(null == _timer || !_timer.isActive);
_timer =
Timer(Duration(milliseconds: max(pause, left)), _nextAnimation);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/typer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class _TyperState extends State<TyperAnimatedTextKit>

@override
void dispose() {
_timer?.cancel();
_controller?.stop();
_controller?.dispose();
super.dispose();
Expand Down Expand Up @@ -207,6 +208,7 @@ class _TyperState extends State<TyperAnimatedTextKit>
void _animationEndCallback(state) {
if (state == AnimationStatus.completed) {
_setPause();
assert(null == _timer || !_timer.isActive);
_timer = Timer(_texts[_index]['pause'], _nextAnimation);
}
}
Expand All @@ -227,6 +229,7 @@ class _TyperState extends State<TyperAnimatedTextKit>

_setPause();

assert(null == _timer || !_timer.isActive);
_timer =
Timer(Duration(milliseconds: max(pause, left)), _nextAnimation);
}
Expand Down

0 comments on commit cb43a4d

Please sign in to comment.