Skip to content

AnimationController should have the ability to repeat n times #53262

@IchordeDionysos

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

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