AnimationController should have the ability to repeat n times #53262
Copy link
Copy link
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: animationAnimation APIsAnimation APIsc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Use case
AnimationController should provide a simple way to repeat n times, currently, this is not possible from what we could find.
This is the nearest and simplest solution: https://stackoverflow.com/questions/59462290/repeating-animations-specific-times-e-g-20-times-by-flutter/59463013#59463013
If an animation should repeat n times, it should do the animation and then jump back to 0 (or 1 for reverse) and do the animation again. Until it reached 1 (or 0 for reverse) n times and then stop there and send a completion event in the status listener.
Proposal
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
)
..repeat(times: 3)
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
print("Has repeated 3 times. Execution took 6 seconds.");
}
});Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: animationAnimation APIsAnimation APIsc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Activity
Nico04 commentedon May 4, 2020
The issue with the stackoverflow implementation is that if you call stop() or reset() before timeout, the onTimeout callback is still executed, which can cause weird behaviour if animation is started again before that timeout.
I've noticed that the repeat() future never complete, is that a Flutter bug ?
angelhdzmultimedia commentedon May 6, 2021
Has this been implemented?
IchordeDionysos commentedon May 8, 2021
No, but should be easily implementable in this file:
https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/animation/animation_controller.dart
By counting/calculating the number of loops in the
_RepeatingSimulation:)KgotsoK commentedon May 11, 2022
Oof This would be especially helpful for Lottie animations too. Sad It's still an open issue.
✨ : flutter#53262 : Animation controller now has ability to repeat an…
aliasgar4558 commentedon Jun 25, 2024
Raised PR for this as a feature.
15 remaining items
✨ : flutter#53262 : Animation controller now has ability to repeat an…
✨ : flutter#53262 : Animation controller now has ability to repeat an…
✨ : flutter#53262 : Animation controller now has ability to repeat an…
✨ : flutter#53262 : Animation controller now has ability to repeat an…
✨ : flutter#53262 : Animation controller now has ability to repeat an…
✨ : flutter#53262 : Animation controller now has ability to repeat an…
✨ : flutter#53262 : Animation controller now has ability to repeat an…
✨ : flutter#53262 : Animation controller now has ability to repeat an…
✨ : Animation controller now has ability to repeat animation 'n' no. …
✨ : Animation controller now has ability to repeat animation 'n' no. …
github-actions commentedon Aug 14, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.✨ : Animation controller now has ability to repeat animation 'n' no. …