Skip to content

Commit

Permalink
Fix leak memory in Tooltip and account detail (#146833)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinVignal authored Apr 16, 2024
1 parent c3445dc commit 3882afb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
10 changes: 9 additions & 1 deletion packages/flutter/lib/src/material/tooltip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,13 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
vsync: this,
)..addStatusListener(_handleStatusChanged);
}
CurvedAnimation? _backingOverlayAnimation;
CurvedAnimation get _overlayAnimation {
return _backingOverlayAnimation ??= CurvedAnimation(
parent: _controller,
curve: Curves.fastOutSlowIn,
);
}

LongPressGestureRecognizer? _longPressRecognizer;
TapGestureRecognizer? _tapRecognizer;
Expand Down Expand Up @@ -796,7 +803,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
decoration: widget.decoration ?? tooltipTheme.decoration ?? defaultDecoration,
textStyle: widget.textStyle ?? tooltipTheme.textStyle ?? defaultTextStyle,
textAlign: widget.textAlign ?? tooltipTheme.textAlign ?? _defaultTextAlign,
animation: CurvedAnimation(parent: _controller, curve: Curves.fastOutSlowIn),
animation:_overlayAnimation,
target: target,
verticalOffset: widget.verticalOffset ?? tooltipTheme.verticalOffset ?? _defaultVerticalOffset,
preferBelow: widget.preferBelow ?? tooltipTheme.preferBelow ?? _defaultPreferBelow,
Expand All @@ -821,6 +828,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
_tapRecognizer?.dispose();
_timer?.cancel();
_backingController?.dispose();
_backingOverlayAnimation?.dispose();
super.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class _AccountDetails extends StatefulWidget {
}

class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProviderStateMixin {
late Animation<double> _animation;
late AnimationController _controller;
late final CurvedAnimation _animation;
late final AnimationController _controller;
@override
void initState () {
super.initState();
Expand All @@ -110,6 +110,7 @@ class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProvi
@override
void dispose() {
_controller.dispose();
_animation.dispose();
super.dispose();
}

Expand Down
6 changes: 5 additions & 1 deletion packages/flutter/test/material/filter_chip_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

import 'feedback_tester.dart';

Expand Down Expand Up @@ -956,7 +957,10 @@ void main() {
expect(getIconData(tester).color, theme.iconTheme.color?.withAlpha(0xde));
});

testWidgets('Customize FilterChip delete button', (WidgetTester tester) async {
testWidgets('Customize FilterChip delete button',
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: const <String>['CurvedAnimation']),
(WidgetTester tester) async {
Widget buildChip({
Widget? deleteIcon,
Color? deleteIconColor,
Expand Down
6 changes: 5 additions & 1 deletion packages/flutter/test/material/input_chip_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ library;
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

/// Adds the basic requirements for a Chip.
Widget wrapForChip({
Expand Down Expand Up @@ -456,7 +457,10 @@ void main() {
await expectLater(find.byType(RawChip), matchesGoldenFile('input_chip.disabled.delete_button.png'));
});

testWidgets('Delete button tooltip is not shown on disabled InputChip', (WidgetTester tester) async {
testWidgets('Delete button tooltip is not shown on disabled InputChip',
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: const <String>['CurvedAnimation']),
(WidgetTester tester) async {
Widget buildChip({ bool enabled = true }) {
return wrapForChip(
child: InputChip(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import '../widgets/semantics_tester.dart';

const Key avatarA = Key('A');
Expand Down Expand Up @@ -261,7 +262,10 @@ void main() {
expect(transformWidget.transform.getRotation()[4], 1.0);
});

testWidgets('UserAccountsDrawerHeader icon color changes', (WidgetTester tester) async {
testWidgets('UserAccountsDrawerHeader icon color changes',
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: const <String>['CurvedAnimation']),
(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: Material(
child: UserAccountsDrawerHeader(
Expand Down

0 comments on commit 3882afb

Please sign in to comment.