From 28240e050c51a58c558321b2a01b3359cad84ccb Mon Sep 17 00:00:00 2001 From: jakeBrightHR <112476079+jakeBrightHR@users.noreply.github.com> Date: Wed, 9 Nov 2022 02:40:56 +0000 Subject: [PATCH] Fix timer issue in unit tests (#27) 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 --- lib/avatar_glow.dart | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/avatar_glow.dart b/lib/avatar_glow.dart index f3c7a82..bc12105 100644 --- a/lib/avatar_glow.dart +++ b/lib/avatar_glow.dart @@ -59,15 +59,18 @@ class _AvatarGlowState extends State end: 0.0, ).animate(_controller); - Future _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() { @@ -168,6 +171,7 @@ class _AvatarGlowState extends State @override void dispose() { + _repeatPauseTimer.cancel(); _controller.dispose(); super.dispose(); }