Skip to content

Commit c643081

Browse files
[flutter_adaptive_scaffold] Fix some memory leaks (#8546)
Fixes some memory leaks See the documentation: https://github.com/dart-lang/leak_tracker/blob/main/doc%2Fleak_tracking%2FDETECT.md
1 parent 7fc4c29 commit c643081

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

packages/flutter_adaptive_scaffold/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
## 0.3.2
2+
3+
* Fixes some memory leaks by disposing curved animations and value notifiers.
4+
15
## 0.3.1+1
26

37
* Updates README to indicate that this package will be discontinued.
48

9+
510
## 0.3.1
611

712
* Use improved MediaQuery methods.

packages/flutter_adaptive_scaffold/lib/src/adaptive_layout.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ class AdaptiveLayout extends StatefulWidget {
206206
class _AdaptiveLayoutState extends State<AdaptiveLayout>
207207
with TickerProviderStateMixin {
208208
late AnimationController _controller;
209+
late final CurvedAnimation _sizeAnimation = CurvedAnimation(
210+
parent: _controller,
211+
curve: Curves.easeInOutCubic,
212+
);
209213

210214
late Map<String, SlotLayoutConfig?> chosenWidgets =
211215
<String, SlotLayoutConfig?>{};
@@ -250,6 +254,10 @@ class _AdaptiveLayoutState extends State<AdaptiveLayout>
250254
@override
251255
void dispose() {
252256
_controller.dispose();
257+
_sizeAnimation.dispose();
258+
for (final ValueNotifier<Key?> notifier in notifiers.values) {
259+
notifier.dispose();
260+
}
253261
super.dispose();
254262
}
255263

@@ -314,6 +322,7 @@ class _AdaptiveLayoutState extends State<AdaptiveLayout>
314322
bodyOrientation: widget.bodyOrientation,
315323
textDirection: Directionality.of(context) == TextDirection.ltr,
316324
hinge: hinge,
325+
sizeAnimation: _sizeAnimation,
317326
),
318327
children: entries,
319328
);
@@ -333,6 +342,7 @@ class _AdaptiveLayoutDelegate extends MultiChildLayoutDelegate {
333342
required this.internalAnimations,
334343
required this.bodyOrientation,
335344
required this.textDirection,
345+
required this.sizeAnimation,
336346
this.hinge,
337347
}) : super(relayout: controller);
338348

@@ -346,6 +356,7 @@ class _AdaptiveLayoutDelegate extends MultiChildLayoutDelegate {
346356
final Axis bodyOrientation;
347357
final bool textDirection;
348358
final Rect? hinge;
359+
final Animation<double> sizeAnimation;
349360

350361
@override
351362
void performLayout(Size size) {
@@ -359,10 +370,7 @@ class _AdaptiveLayoutDelegate extends MultiChildLayoutDelegate {
359370
double animatedSize(double begin, double end) {
360371
if (isAnimating.contains(_SlotIds.secondaryBody.name)) {
361372
return internalAnimations
362-
? Tween<double>(begin: begin, end: end)
363-
.animate(CurvedAnimation(
364-
parent: controller, curve: Curves.easeInOutCubic))
365-
.value
373+
? Tween<double>(begin: begin, end: end).animate(sizeAnimation).value
366374
: end;
367375
}
368376
return end;

packages/flutter_adaptive_scaffold/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_adaptive_scaffold
22
description: Widgets to easily build adaptive layouts, including navigation elements.
3-
version: 0.3.1+1
3+
version: 0.3.2
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_adaptive_scaffold%22
55
repository: https://github.com/flutter/packages/tree/main/packages/flutter_adaptive_scaffold
66

0 commit comments

Comments
 (0)