Skip to content

[Breaking Change] Disambiguate CurvedAnimation and CurveTween #185468

Description

@adil192

Use case

Currently, it's ambiguous for a user whether to use CurvedAnimation or CurveTween. The new documentation in #184569 helps, but it's ultimately just a band-aid highlighting a confusing API.

I see the issue being that CurvedAnimation and CurveTween do exactly the same thing in the common case where CurvedAnimation.reverseCurve is not used. Therefore, we should discourage using CurvedAnimation without a reverseCurve in some intuitive way.

This proposal follows on from an unanswered question in #183292 (comment) (but slightly different).

Proposal

This has since been reworked: see the below comment
Here is the original proposal...

Rename CurvedAnimation to ReversibleCurvedAnimation, and make CurvedAnimation.reverseCurve a required argument:

-  CurvedAnimation({required this.parent, required this.curve, this.reverseCurve}) {
+  ReversibleCurvedAnimation({required this.parent, required this.curve, required this.reverseCurve}) {

This is a breaking change, and users are advised to migrate in one of the following ways:

  • If reverseCurve is not needed, use CurveTween.
  • If reverseCurve is needed and specified, replace with ReversibleCurvedAnimation.
  • If reverseCurve is needed but not specified at instantiation, replace with ReversibleCurvedAnimation and explicitly specify reverseCurve as null.

I will make a pull request shortly. I'm currently adding data-driven fixes and updating all the examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: animationAnimation APIsc: API breakBackwards-incompatible API changesc: proposalA detailed proposal for a change to Flutterd: api docsIssues with https://api.flutter.dev/team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions