From e6d3208c914a803d15558c3881bcadc203645b45 Mon Sep 17 00:00:00 2001 From: Rafael Winter Date: Wed, 1 Apr 2026 18:01:46 -0300 Subject: [PATCH] Fix CurvedAnimation leak in EffectEntry.buildAnimation (#155) Replace CurvedAnimation with CurveTween + Animation.drive to avoid creating disposable objects during the build phase that are never disposed, which causes memory leaks. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/src/flutter_animate.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/src/flutter_animate.dart b/lib/src/flutter_animate.dart index e385114..5cce8a9 100644 --- a/lib/src/flutter_animate.dart +++ b/lib/src/flutter_animate.dart @@ -50,15 +50,19 @@ class EffectEntry { Duration get end => delay + duration; /// Builds a sub-animation based on the properties of this entry. + /// + /// Uses [CurveTween] with [Animation.drive] instead of [CurvedAnimation] + /// to avoid creating a disposable object on every call. This method is + /// invoked from [Effect.build] during the widget build phase, so using + /// [CurvedAnimation] would leak instances since they are never disposed. Animation buildAnimation( AnimationController controller, { Curve? curve, }) { int ttlT = controller.duration?.inMicroseconds ?? 0; int beginT = begin.inMicroseconds, endT = end.inMicroseconds; - return CurvedAnimation( - parent: controller, - curve: Interval(beginT / ttlT, endT / ttlT, curve: curve ?? this.curve), + return controller.drive( + CurveTween(curve: Interval(beginT / ttlT, endT / ttlT, curve: curve ?? this.curve)), ); } }