Skip to content

Commit

Permalink
TickerProvider -> Singletickerprovider (#124)
Browse files Browse the repository at this point in the history
* changes made to fade (#119)

* changes made in rotate (#119)

* changes made in scale (#119)

* TickerProvider->SingleTickerProvider (fade)(#119)
  • Loading branch information
SirusCodes committed Oct 13, 2020
1 parent cb43a4d commit 28ab296
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 82 deletions.
35 changes: 19 additions & 16 deletions lib/src/fade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class FadeAnimatedTextKit extends StatefulWidget {
}

class _FadeTextState extends State<FadeAnimatedTextKit>
with TickerProviderStateMixin {
with SingleTickerProviderStateMixin {
Animation _fadeIn, _fadeOut;

AnimationController _controller;
Expand Down Expand Up @@ -135,6 +135,7 @@ class _FadeTextState extends State<FadeAnimatedTextKit>
_texts.add({'text': text, 'pause': _pause});
});

_initAnimation();
_nextAnimation();
}

Expand Down Expand Up @@ -171,6 +172,22 @@ class _FadeTextState extends State<FadeAnimatedTextKit>
);
}

void _initAnimation() {
_controller = AnimationController(
duration: _duration,
vsync: this,
);

_fadeIn = Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.0, 0.5, curve: Curves.linear)));

_fadeOut = Tween<double>(begin: 1.0, end: 0.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.8, 1.0, curve: Curves.linear)))
..addStatusListener(_animationEndCallback);
}

void _nextAnimation() {
final bool isLast = _index == widget.text.length - 1;

Expand Down Expand Up @@ -199,21 +216,7 @@ class _FadeTextState extends State<FadeAnimatedTextKit>

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

_controller = AnimationController(
duration: _duration,
vsync: this,
);

_fadeIn = Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.0, 0.5, curve: Curves.linear)));

_fadeOut = Tween<double>(begin: 1.0, end: 0.0).animate(CurvedAnimation(
parent: _controller,
curve: const Interval(0.8, 1.0, curve: Curves.linear)))
..addStatusListener(_animationEndCallback);

_controller.forward();
_controller.forward(from: 0.0);
}

void _setPause() {
Expand Down
75 changes: 39 additions & 36 deletions lib/src/rotate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class RotateAnimatedTextKit extends StatefulWidget {
}

class _RotatingTextState extends State<RotateAnimatedTextKit>
with TickerProviderStateMixin {
with SingleTickerProviderStateMixin {
AnimationController _controller;

double _transitionHeight;
Expand Down Expand Up @@ -137,6 +137,7 @@ class _RotatingTextState extends State<RotateAnimatedTextKit>
_texts.add({'text': text, 'pause': _pause});
});

_initAnimation();
_nextAnimation();
}

Expand Down Expand Up @@ -179,40 +180,7 @@ class _RotatingTextState extends State<RotateAnimatedTextKit>
);
}

void _nextAnimation() {
final bool isLast = _index == widget.text.length - 1;

_isCurrentlyPausing = false;

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

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

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

if (widget.transitionHeight == null) {
_transitionHeight = widget.textStyle.fontSize * 10 / 3;
} else {
_transitionHeight = widget.transitionHeight;
}

void _initAnimation() {
_controller = AnimationController(
duration: _duration,
vsync: this,
Expand Down Expand Up @@ -253,8 +221,43 @@ class _RotatingTextState extends State<RotateAnimatedTextKit>
parent: _controller,
curve: const Interval(0.7, 1.0, curve: Curves.easeIn)))
..addStatusListener(_animationEndCallback);
}

void _nextAnimation() {
final bool isLast = _index == widget.text.length - 1;

_isCurrentlyPausing = false;

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

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

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

if (widget.transitionHeight == null) {
_transitionHeight = widget.textStyle.fontSize * 10 / 3;
} else {
_transitionHeight = widget.transitionHeight;
}

_controller.forward();
_controller.forward(from: 0.0);
}

void _setPause() {
Expand Down
64 changes: 34 additions & 30 deletions lib/src/scale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ScaleAnimatedTextKit extends StatefulWidget {
}

class _ScaleTextState extends State<ScaleAnimatedTextKit>
with TickerProviderStateMixin {
with SingleTickerProviderStateMixin {
AnimationController _controller;

Animation _fadeIn, _fadeOut, _scaleIn, _scaleOut;
Expand Down Expand Up @@ -141,6 +141,8 @@ class _ScaleTextState extends State<ScaleAnimatedTextKit>
_texts.add({'text': text, 'pause': _pause});
});

// init controller and animations
_initAnimation();
// Start animation
_nextAnimation();
}
Expand Down Expand Up @@ -181,34 +183,7 @@ class _ScaleTextState extends State<ScaleAnimatedTextKit>
);
}

void _nextAnimation() {
final bool isLast = _index == widget.text.length - 1;

_isCurrentlyPausing = false;

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

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

setState(() {});

void _initAnimation() {
_controller = AnimationController(
duration: _duration,
vsync: this,
Expand Down Expand Up @@ -239,8 +214,37 @@ class _ScaleTextState extends State<ScaleAnimatedTextKit>
curve: Curves.easeIn,
)))
..addStatusListener(_animationEndCallback);
}

void _nextAnimation() {
final bool isLast = _index == widget.text.length - 1;

_isCurrentlyPausing = false;

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

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

setState(() {});

_controller.forward();
_controller.forward(from: 0.0);
}

void _setPause() {
Expand Down

0 comments on commit 28ab296

Please sign in to comment.