hnvn / flutter_shimmer

A package provides an easy way to add shimmer effect in Flutter project
BSD 3-Clause "New" or "Revised" License
1.77k stars 200 forks source link

AnimationController methods were called after calling dispose. #72

Open nihil-sine-nikhil opened 6 months ago

nihil-sine-nikhil commented 6 months ago

Issue Description: When using the AnimationController in Flutter, there is an issue where calling AnimationController.forward() after the controller has been disposed results in the following error:

flutter: AnimationController.forward() called after AnimationController.dispose()
flutter: AnimationController methods should not be used after calling dispose.

Solution Summary of Changes: To address this issue, I have added a check for the "mounted" property before calling AnimationController.forward(). This ensures that the animation controller is not used after it has been disposed, preventing the error mentioned above.

Code Changes image

Context This change is essential to prevent the usage of the AnimationController after it has been disposed. The mounted property is a reliable way to determine if the widget is still part of the widget tree, and thus, it's safe to call AnimationController.forward().

Testing I have added relevant tests to ensure that the issue is resolved and that the animation controller is only forwarded when the widget is still mounted.

Reviewer Notes Please review the changes and confirm that the fix effectively addresses the issue without introducing any regressions. Pay special attention to the added tests and verify that they cover the scenarios related to the problem.