Skip to content

AnimationController should have the ability to repeat n times #53262

Closed

Description

@IchordeDionysos

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.");
    }
});

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    c: new featureNothing broken; request for a new capability
    on Mar 25, 2020
  2. Nico04 commented on May 4, 2020

    @Nico04

    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 ?

  3. angelhdzmultimedia commented on May 6, 2021

    @angelhdzmultimedia

    Has this been implemented?

  4. IchordeDionysos commented on May 8, 2021

    @IchordeDionysos
    ContributorAuthor

    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 :)

  5. KgotsoK commented on May 11, 2022

    @KgotsoK

    Oof This would be especially helpful for Lottie animations too. Sad It's still an open issue.

  6. added
    P3Issues that are less important to the Flutter project
    and removed on Jun 28, 2023
  7. added a commit that references this issue on Jun 25, 2024
  8. aliasgar4558 commented on Jun 25, 2024

    @aliasgar4558
    Contributor

    Raised PR for this as a feature.

  9. 15 remaining items

  10. added 8 commits that reference this issue on Jul 19, 2024
  11. github-actions commented on Aug 14, 2024

    @github-actions

    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 -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: animationAnimation APIsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions