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

Can use SingleTickerProviderStateMixin #119

Closed
SirusCodes opened this issue Oct 11, 2020 · 13 comments · Fixed by #124
Closed

Can use SingleTickerProviderStateMixin #119

SirusCodes opened this issue Oct 11, 2020 · 13 comments · Fixed by #124

Comments

@SirusCodes
Copy link
Collaborator

We can use SingleTickerProviderStateMixin in almost all of animations.

Current implementation
We are calling setting _controller and Animation each time

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

Better implementation
We set _controller and Animation in initState an call forward each time

_controller.forward(from:  0.0);

This will reduce the calls which we are making in each cycle. Using SingleTickerProviderStateMixin is more efficient than TickerProviderStateMixin.

If you want I would like to collaborate on this.

@awhitford
Copy link
Collaborator

Are you willing to submit a PR?

@SirusCodes
Copy link
Collaborator Author

Yup I can do that

@SirusCodes
Copy link
Collaborator Author

SirusCodes commented Oct 11, 2020

Hey I have made the changes but I'm getting AnimationController methods should not be used after calling dispose. error when I'm changing the animation view in pause duration. All the disposes are in proper position.

@awhitford
Copy link
Collaborator

@SirusCodes Which class? Looking at Fade, as an example, _controller?.dispose(); is only called during the dispose method, so that seems fine. A stack trace may be helpful.

@SirusCodes
Copy link
Collaborator Author

Sorry I should have provided this earlier only.

E/flutter (11494): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: 'package:flutter/src/animation/animation_controller.dart': Failed assertion: line 456 pos 7: '_ticker != null': AnimationController.forward() called after AnimationController.dispose()
E/flutter (11494): AnimationController methods should not be used after calling dispose.
E/flutter (11494): #0      _AssertionError._doThrowNew  (dart:core-patch/errors_patch.dart:46:39))
E/flutter (11494): #1      _AssertionError._throwNew  (dart:core-patch/errors_patch.dart:36:5))
E/flutter (11494): #2      AnimationController.forward 
package:flutter/…/animation/animation_controller.dart:456
E/flutter (11494): #3      _RotatingTextState._nextAnimation 
package:animated_text_kit/src/rotate.dart:259
E/flutter (11494): #4      _rootRun  (dart:async/zone.dart:1182:47))
E/flutter (11494): #5      _CustomZone.run  (dart:async/zone.dart:1093:19))
E/flutter (11494): #6      _CustomZone.runGuarded  (dart:async/zone.dart:997:7))
E/flutter (11494): #7      _CustomZone.bindCallbackGuarded.<anonymous closure>  (dart:async/zone.dart:1037:23))
E/flutter (11494): #8      _rootRun  (dart:async/zone.dart:1190:13))
E/flutter (11494): #9      _CustomZone.run  (dart:async/zone.dart:1093:19))
E/flutter (11494): #10     _CustomZone.bindCallback.<anonymous closure>  (dart:async/zone.dart:1021:23))
E/flutter (11494): #11     Timer._createTimer.<anonymous closure>  (dart:async-patch/timer_patch.dart:18:15))
E/flutter (11494): #12     _Timer._runTimers  (dart:isolate-patch/timer_impl.dart:397:19))
E/flutter (11494): #13     _Timer._handleMessage  (dart:isolate-patch/timer_impl.dart:428:5))
E/flutter (11494): #14     _RawReceivePortImpl._handleMessage  (dart:isolate-patch/isolate_patch.dart:168:12))
E/flutter (11494):

@awhitford
Copy link
Collaborator

Since I do not see your changes, it is challenging to imagine that the issue may be.

Maybe you can debug it by putting a breakpoint on AnimationController.dispose and seeing when it is called. It should only be called when the widget is being disposed, but maybe there is something unexpected?

Also, I assume that the AnimationController is created in the State.initState method and then disposed in the State.dispose method, as prescribed?

@SirusCodes
Copy link
Collaborator Author

Yes I have properly initialised and disposed AnimationController. Will try to add breakpoints and figure out what is the problem tomorrow 👍

@SirusCodes
Copy link
Collaborator Author

SirusCodes commented Oct 11, 2020

I guess I got the issue.
When I change the screen the AnimationController is disposed but Timer is waiting to complete and when it completes it calls the _next function which calls _controller.forward().

I need to stop timer or something else to stop it from calling _next() when dispose is called.

@awhitford
Copy link
Collaborator

I just submitted PR #121 for Fade, based on issue #98. It sounds like you have a similar issue.

@SirusCodes
Copy link
Collaborator Author

Yes, timer in all the animations are not handled properly...it would be great if you can do that and after your PR is merge I would create my PR.

@awhitford
Copy link
Collaborator

Fade is fixed by PR #121, PR #122 fixes Typewriter, and PR #123 fixes the rest (Rotate, Scale, and Typer).

@SirusCodes
Copy link
Collaborator Author

You can expect a PR by tonight 👍

awhitford pushed a commit that referenced this issue Oct 13, 2020
* changes made to fade (#119)

* changes made in rotate (#119)

* changes made in scale (#119)

* TickerProvider->SingleTickerProvider (fade)(#119)
@aagarwal1012
Copy link
Owner

#124 fixes this issue!

@aagarwal1012 aagarwal1012 linked a pull request Oct 14, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants