From 253805e1b1c0d599d402a4be1fc10c9dd80964be Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Sat, 1 Feb 2025 22:33:39 +0800 Subject: [PATCH 1/2] Fix some memory leaks --- .../lib/src/adaptive_layout.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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; From ee55a42cddf7d8be98e190c67762d6cbc7e89e94 Mon Sep 17 00:00:00 2001 From: ValentinVignal Date: Sat, 1 Feb 2025 22:37:52 +0800 Subject: [PATCH 2/2] Update version number --- packages/flutter_adaptive_scaffold/CHANGELOG.md | 4 ++++ packages/flutter_adaptive_scaffold/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/flutter_adaptive_scaffold/CHANGELOG.md b/packages/flutter_adaptive_scaffold/CHANGELOG.md index 69ffdcd0a51..eade279ba3f 100644 --- a/packages/flutter_adaptive_scaffold/CHANGELOG.md +++ b/packages/flutter_adaptive_scaffold/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.2 + +* Fixes some memory leaks by disposing curved animations and value notifiers. + ## 0.3.1 * Use improved MediaQuery methods. diff --git a/packages/flutter_adaptive_scaffold/pubspec.yaml b/packages/flutter_adaptive_scaffold/pubspec.yaml index 258d9bcc6a7..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 +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