Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Fix some memory leaks
  • Loading branch information
ValentinVignal committed Feb 1, 2025
commit 253805e1b1c0d599d402a4be1fc10c9dd80964be
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