Skip to content

Commit

Permalink
Fix timer issue in unit tests (#27)
Browse files Browse the repository at this point in the history
Create a Timer variable to store the repeatPauseDuration.

We can then cancel this Timer in the onDispose() method.

This fixes the FakeTimer error when using this Widget in unit tests
  • Loading branch information
jakeBrightHR committed Nov 9, 2022
1 parent c5740f9 commit 28240e0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/avatar_glow.dart
Expand Up @@ -59,15 +59,18 @@ class _AvatarGlowState extends State<AvatarGlow>
end: 0.0,
).animate(_controller);

Future<void> _statusListener(AnimationStatus status) async {
if (_controller.status == AnimationStatus.completed) {
await Future.delayed(widget.repeatPauseDuration);
if (mounted && widget.repeat && widget.animate) {
_controller.reset();
_controller.forward();
}
late Timer _repeatPauseTimer;

late void Function(AnimationStatus status) _statusListener = (_) async {
if (controller.status == AnimationStatus.completed) {
_repeatPauseTimer = Timer(widget.repeatPauseDuration, () {
if (mounted && widget.repeat && widget.animate) {
controller.reset();
controller.forward();
}
});
}
}
};

@override
void initState() {
Expand Down Expand Up @@ -168,6 +171,7 @@ class _AvatarGlowState extends State<AvatarGlow>

@override
void dispose() {
_repeatPauseTimer.cancel();
_controller.dispose();
super.dispose();
}
Expand Down

0 comments on commit 28240e0

Please sign in to comment.