Skip to content

Commit

Permalink
use CurveTween instead of CurvedAnimation
Browse files Browse the repository at this point in the history
avoids memory leaks
  • Loading branch information
baumths committed May 4, 2024
1 parent 528f29b commit fca2151
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/src/sliver_animated_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class _SliverAnimatedTreeState<T extends Object>
final GlobalKey<SliverAnimatedListState> _listKey =
GlobalKey<SliverAnimatedListState>();

late final CurveTween _curveTween = CurveTween(curve: widget.curve);
List<TreeEntry<T>> _flatTree = const [];

void _rebuild() {
Expand Down Expand Up @@ -158,7 +159,7 @@ class _SliverAnimatedTreeState<T extends Object>
return widget.transitionBuilder(
context,
widget.nodeBuilder(context, entry),
CurvedAnimation(parent: animation, curve: widget.curve),
_curveTween.animate(animation),
);
},
);
Expand Down Expand Up @@ -188,6 +189,7 @@ class _SliverAnimatedTreeState<T extends Object>
widget.controller.addListener(_animatedRebuild);
_rebuild();
}
_curveTween.curve = widget.curve;
}

@override
Expand All @@ -212,7 +214,7 @@ class _SliverAnimatedTreeState<T extends Object>
return widget.transitionBuilder(
context,
widget.nodeBuilder(context, _flatTree[index]),
CurvedAnimation(parent: animation, curve: widget.curve),
_curveTween.animate(animation),
);
},
),
Expand Down

0 comments on commit fca2151

Please sign in to comment.