diff --git a/packages/flutter_adaptive_scaffold/CHANGELOG.md b/packages/flutter_adaptive_scaffold/CHANGELOG.md index 6485408a584..dfedd2e7cf3 100644 --- a/packages/flutter_adaptive_scaffold/CHANGELOG.md +++ b/packages/flutter_adaptive_scaffold/CHANGELOG.md @@ -1,7 +1,12 @@ +## 0.3.2 + +* Fixes some memory leaks by disposing curved animations and value notifiers. + ## 0.3.1+1 * Updates README to indicate that this package will be discontinued. + ## 0.3.1 * Use improved MediaQuery methods. diff --git a/packages/flutter_adaptive_scaffold/lib/src/adaptive_layout.dart b/packages/flutter_adaptive_scaffold/lib/src/adaptive_layout.dart index 50fd625917c..dd234c9e8b8 100644 --- a/packages/flutter_adaptive_scaffold/lib/src/adaptive_layout.dart +++ b/packages/flutter_adaptive_scaffold/lib/src/adaptive_layout.dart @@ -206,6 +206,10 @@ class AdaptiveLayout extends StatefulWidget { class _AdaptiveLayoutState extends State with TickerProviderStateMixin { late AnimationController _controller; + late final CurvedAnimation _sizeAnimation = CurvedAnimation( + parent: _controller, + curve: Curves.easeInOutCubic, + ); late Map chosenWidgets = {}; @@ -250,6 +254,10 @@ class _AdaptiveLayoutState extends State @override void dispose() { _controller.dispose(); + _sizeAnimation.dispose(); + for (final ValueNotifier notifier in notifiers.values) { + notifier.dispose(); + } super.dispose(); } @@ -314,6 +322,7 @@ class _AdaptiveLayoutState extends State bodyOrientation: widget.bodyOrientation, textDirection: Directionality.of(context) == TextDirection.ltr, hinge: hinge, + sizeAnimation: _sizeAnimation, ), children: entries, ); @@ -333,6 +342,7 @@ class _AdaptiveLayoutDelegate extends MultiChildLayoutDelegate { required this.internalAnimations, required this.bodyOrientation, required this.textDirection, + required this.sizeAnimation, this.hinge, }) : super(relayout: controller); @@ -346,6 +356,7 @@ class _AdaptiveLayoutDelegate extends MultiChildLayoutDelegate { final Axis bodyOrientation; final bool textDirection; final Rect? hinge; + final Animation sizeAnimation; @override void performLayout(Size size) { @@ -359,10 +370,7 @@ class _AdaptiveLayoutDelegate extends MultiChildLayoutDelegate { double animatedSize(double begin, double end) { if (isAnimating.contains(_SlotIds.secondaryBody.name)) { return internalAnimations - ? Tween(begin: begin, end: end) - .animate(CurvedAnimation( - parent: controller, curve: Curves.easeInOutCubic)) - .value + ? Tween(begin: begin, end: end).animate(sizeAnimation).value : end; } return end; diff --git a/packages/flutter_adaptive_scaffold/pubspec.yaml b/packages/flutter_adaptive_scaffold/pubspec.yaml index c4c76c86a4c..76197a98d19 100644 --- a/packages/flutter_adaptive_scaffold/pubspec.yaml +++ b/packages/flutter_adaptive_scaffold/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_adaptive_scaffold description: Widgets to easily build adaptive layouts, including navigation elements. -version: 0.3.1+1 +version: 0.3.2 issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_adaptive_scaffold%22 repository: https://github.com/flutter/packages/tree/main/packages/flutter_adaptive_scaffold