Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using new parameter 'interval' (v. 0.2.0) causes exception #11

Closed
budo76 opened this issue Oct 12, 2020 · 4 comments
Closed

Using new parameter 'interval' (v. 0.2.0) causes exception #11

budo76 opened this issue Oct 12, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@budo76
Copy link

budo76 commented Oct 12, 2020

When the widget is removed from the widget tree it still tries to animate, causing the following exception:

AnimationController methods should not be used after calling dispose.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
#2      AnimationController.forward (package:flutter/src/animation/animation_controller.dart:456:7)
#3      _ShimmerAnimatorState.initState.<anonymous closure>.<anonymous closure> (package:shimmer_animation/src/shimmer_animator.dart:40:60)
 #4      new Future.delayed.<anonymous closure> (dart:async/future.dart:326:39)

In brief the internally used AnimationController has already been disposed (correctly) when the internal Future (used to delay the shimmer) tries to animate forward.

To reproduce the problem just create a basic app with a button to perform a Navigator.push to push a route, with a Page that use the Shimmer with the "interval" param, and then just press "back" or programmatically add a button to perform the Navigator.pop in order to remove the Shimmer widget from the widget-tree. Wait the 'interval' delay to see the exception.

@budo76 budo76 added the bug Something isn't working label Oct 12, 2020
@budo76
Copy link
Author

budo76 commented Oct 12, 2020

Perhaps at line 40 of shimmer_animator.dart you just need to check the mounted property of the State. Something like:

[...] // line 37
..addListener(() async {
        if (controller.isCompleted)
          Future.delayed(widget.interval, () {
            if (mounted) controller.forward(from: 0);
          });
[...]

... in theory after the widget is removed from the tree (disposed) the state is unmonted so it will never try to animate after that.

EDIT: I tested this change (directly modifying the sources from the flutter directory) and it works, so it would be useful to integrate this patch in the project for next release...

@maddyb99
Copy link
Owner

Thank you for raising this issue. I would integrate this ASAP or would you like to open a Pull request, since I see that you have already tried and tested this?

@budo76
Copy link
Author

budo76 commented Oct 12, 2020 via email

@maddyb99
Copy link
Owner

I totally agree, will do it, its just that I won't be able to push it out now due to some reasons, would try to do it in a couple of days!

Thanks again for sharing this 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants