Skip to content

[flutter_adaptive_scaffold] Fix some memory leaks [prod-leak-fix] #8546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/flutter_adaptive_scaffold/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
16 changes: 12 additions & 4 deletions packages/flutter_adaptive_scaffold/lib/src/adaptive_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ class AdaptiveLayout extends StatefulWidget {
class _AdaptiveLayoutState extends State<AdaptiveLayout>
with TickerProviderStateMixin {
late AnimationController _controller;
late final CurvedAnimation _sizeAnimation = CurvedAnimation(
parent: _controller,
curve: Curves.easeInOutCubic,
);

late Map<String, SlotLayoutConfig?> chosenWidgets =
<String, SlotLayoutConfig?>{};
Expand Down Expand Up @@ -250,6 +254,10 @@ class _AdaptiveLayoutState extends State<AdaptiveLayout>
@override
void dispose() {
_controller.dispose();
_sizeAnimation.dispose();
for (final ValueNotifier<Key?> notifier in notifiers.values) {
notifier.dispose();
}
super.dispose();
}

Expand Down Expand Up @@ -314,6 +322,7 @@ class _AdaptiveLayoutState extends State<AdaptiveLayout>
bodyOrientation: widget.bodyOrientation,
textDirection: Directionality.of(context) == TextDirection.ltr,
hinge: hinge,
sizeAnimation: _sizeAnimation,
),
children: entries,
);
Expand All @@ -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);

Expand All @@ -346,6 +356,7 @@ class _AdaptiveLayoutDelegate extends MultiChildLayoutDelegate {
final Axis bodyOrientation;
final bool textDirection;
final Rect? hinge;
final Animation<double> sizeAnimation;

@override
void performLayout(Size size) {
Expand All @@ -359,10 +370,7 @@ class _AdaptiveLayoutDelegate extends MultiChildLayoutDelegate {
double animatedSize(double begin, double end) {
if (isAnimating.contains(_SlotIds.secondaryBody.name)) {
return internalAnimations
? Tween<double>(begin: begin, end: end)
.animate(CurvedAnimation(
parent: controller, curve: Curves.easeInOutCubic))
.value
? Tween<double>(begin: begin, end: end).animate(sizeAnimation).value
: end;
}
return end;
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_adaptive_scaffold/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand Down