Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
title: Deprecate `CurvedAnimation.reverseCurve` in favor of `AsymmetricCurvedAnimation`
description: >-
CurvedAnimation is becoming a single-curve animation.
Use AsymmetricCurvedAnimation for different curves in
the forward and reverse directions.
---

{% render "docs/breaking-changes.md" %}

## Summary

[`CurvedAnimation`][]'s [`reverseCurve`][] field has been deprecated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The link [reverseCurve][] currently points to AsymmetricCurvedAnimation/reverseCurve.html. Since this sentence refers to the deprecated field on CurvedAnimation, it should point to CurvedAnimation/reverseCurve.html instead. We can define a specific reference link [CurvedAnimation.reverseCurve] at the bottom of the file and use it here.

Suggested change
[`CurvedAnimation`][]'s [`reverseCurve`][] field has been deprecated.
[`CurvedAnimation`][]'s [`reverseCurve`][CurvedAnimation.reverseCurve] field has been deprecated.


To use distinct curves for forward and reverse directions,
switch from [`CurvedAnimation`][] to [`AsymmetricCurvedAnimation`][].

## Background

To support its [`reverseCurve`][] functionality,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The link [reverseCurve][] here refers to the functionality of CurvedAnimation, so it should point to CurvedAnimation/reverseCurve.html instead of AsymmetricCurvedAnimation/reverseCurve.html.

Suggested change
To support its [`reverseCurve`][] functionality,
To support its [`reverseCurve`][CurvedAnimation.reverseCurve] functionality,

`CurvedAnimation` had to add listeners to its [`parent`][]
to keep track of its direction.
If you forget to call the [`dispose`][] method when you're done,
those listeners would stick around in memory and prevent Dart from
freeing up unneeded resources.

But the most common use case of `CurvedAnimation` is with a single curve,
meaning these listeners aren't even needed most of the time.

For this reason, [`reverseCurve`][] is being removed from [`CurvedAnimation`][]
and moved to [`AsymmetricCurvedAnimation`][].

After a migration period,
it will be removed from `CurvedAnimation` alongside its listeners.
This means more memory safety with [`CurvedAnimation`][] and
less code to write, since you won't need to dispose it.

:::note
Until the migration period is over,
remember to still call [`dispose`] when you're done.

If you use [`AsymmetricCurvedAnimation`][],
you still need to call its [`dispose`][] method regardless.
:::
Comment thread
adil192 marked this conversation as resolved.

## Migration guide

If you need [`CurvedAnimation`][]'s [`reverseCurve`][] field,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The link [reverseCurve][] here refers to CurvedAnimation's field, so it should point to CurvedAnimation/reverseCurve.html.

Suggested change
If you need [`CurvedAnimation`][]'s [`reverseCurve`][] field,
If you need [`CurvedAnimation`][]'s [`reverseCurve`][CurvedAnimation.reverseCurve] field,

switch from [`CurvedAnimation`][] to [`AsymmetricCurvedAnimation`][].

Code before migration:

```dart
// This doesn't use `reverseCurve` so it stays as `CurvedAnimation`:
final oneCurve = CurvedAnimation(
parent: _animationController,
curve: Curves.easeIn,
);

// This uses `reverseCurve` so migrate to `AsymmetricCurvedAnimation`:
final twoCurves = CurvedAnimation(
parent: _animationController,
curve: Curves.easeIn,
reverseCurve: Curves.easeOut,
);
```

Code after migration:

```dart
// This doesn't use `reverseCurve` so it stays as `CurvedAnimation`:
final oneCurve = CurvedAnimation(
parent: _animationController,
curve: Curves.easeIn,
);

// This uses `reverseCurve` so migrate to `AsymmetricCurvedAnimation`:
final twoCurves = AsymmetricCurvedAnimation(
parent: _animationController,
curve: Curves.easeIn,
reverseCurve: Curves.easeOut,
);
```

## Timeline

Landed in version: Not yet<br>
In stable release: Not yet

## References

{% render "docs/main-api.md", site: site %}

API documentation:

* [`CurvedAnimation`][]
* [`AsymmetricCurvedAnimation`][]

Relevant issues:

* [Disambiguate CurvedAnimation and CurveTween][]
* [Docs should instruct user to dispose `CurvedAnimation`][]

Relevant PRs:

* [Deprecate `CurvedAnimation.reverseCurve` for `AsymmetricCurvedAnimation`][]

[`AsymmetricCurvedAnimation`]: {{site.main-api}}/flutter/animation/AsymmetricCurvedAnimation-class.html
[`CurvedAnimation`]: {{site.main-api}}/flutter/animation/CurvedAnimation-class.html
[`dispose`]: {{site.main-api}}/flutter/animation/AsymmetricCurvedAnimation/dispose.html
[`parent`]: {{site.main-api}}/flutter/animation/CurvedAnimation/parent.html
[`reverseCurve`]: {{site.main-api}}/flutter/animation/AsymmetricCurvedAnimation/reverseCurve.html
Comment on lines +106 to +108

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Add the new reference link definitions for CurvedAnimation.dispose and CurvedAnimation.reverseCurve to ensure the links resolve correctly.

Suggested change
[`dispose`]: {{site.main-api}}/flutter/animation/AsymmetricCurvedAnimation/dispose.html
[`parent`]: {{site.main-api}}/flutter/animation/CurvedAnimation/parent.html
[`reverseCurve`]: {{site.main-api}}/flutter/animation/AsymmetricCurvedAnimation/reverseCurve.html
[CurvedAnimation.dispose]: {{site.main-api}}/flutter/animation/CurvedAnimation/dispose.html
[CurvedAnimation.reverseCurve]: {{site.main-api}}/flutter/animation/CurvedAnimation/reverseCurve.html
[`dispose`]: {{site.main-api}}/flutter/animation/AsymmetricCurvedAnimation/dispose.html
[`parent`]: {{site.main-api}}/flutter/animation/CurvedAnimation/parent.html
[`reverseCurve`]: {{site.main-api}}/flutter/animation/AsymmetricCurvedAnimation/reverseCurve.html


[Disambiguate CurvedAnimation and CurveTween]: {{site.repo.flutter}}/issues/185468
[Docs should instruct user to dispose `CurvedAnimation`]: {{site.repo.flutter}}/issues/183292
[Deprecate `CurvedAnimation.reverseCurve` for `AsymmetricCurvedAnimation`]: {{site.repo.flutter}}/pull/185797
2 changes: 2 additions & 0 deletions sites/docs/src/content/release/breaking-changes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ They're sorted by release and listed in alphabetical order:

### Not yet released to stable

* [Deprecate `CurvedAnimation.reverseCurve` in favor of `AsymmetricCurvedAnimation`][]
* [Large screen orientation and resizability restrictions ignored on Android 17][]

[Deprecate `CurvedAnimation.reverseCurve` in favor of `AsymmetricCurvedAnimation`]: /release/breaking-changes/deprecate-curved-animation-reverse-curve
[Large screen orientation and resizability restrictions ignored on Android 17]: /release/breaking-changes/android-large-screens-restrictions-ignored

<a id="released-in-flutter-344" aria-hidden="true"></a>
Expand Down
Loading