Skip to content

Commit 3882afb

Browse files
Fix leak memory in Tooltip and account detail (#146833)
1 parent c3445dc commit 3882afb

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

packages/flutter/lib/src/material/tooltip.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,13 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
455455
vsync: this,
456456
)..addStatusListener(_handleStatusChanged);
457457
}
458+
CurvedAnimation? _backingOverlayAnimation;
459+
CurvedAnimation get _overlayAnimation {
460+
return _backingOverlayAnimation ??= CurvedAnimation(
461+
parent: _controller,
462+
curve: Curves.fastOutSlowIn,
463+
);
464+
}
458465

459466
LongPressGestureRecognizer? _longPressRecognizer;
460467
TapGestureRecognizer? _tapRecognizer;
@@ -796,7 +803,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
796803
decoration: widget.decoration ?? tooltipTheme.decoration ?? defaultDecoration,
797804
textStyle: widget.textStyle ?? tooltipTheme.textStyle ?? defaultTextStyle,
798805
textAlign: widget.textAlign ?? tooltipTheme.textAlign ?? _defaultTextAlign,
799-
animation: CurvedAnimation(parent: _controller, curve: Curves.fastOutSlowIn),
806+
animation:_overlayAnimation,
800807
target: target,
801808
verticalOffset: widget.verticalOffset ?? tooltipTheme.verticalOffset ?? _defaultVerticalOffset,
802809
preferBelow: widget.preferBelow ?? tooltipTheme.preferBelow ?? _defaultPreferBelow,
@@ -821,6 +828,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
821828
_tapRecognizer?.dispose();
822829
_timer?.cancel();
823830
_backingController?.dispose();
831+
_backingOverlayAnimation?.dispose();
824832
super.dispose();
825833
}
826834

packages/flutter/lib/src/material/user_accounts_drawer_header.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class _AccountDetails extends StatefulWidget {
8787
}
8888

8989
class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProviderStateMixin {
90-
late Animation<double> _animation;
91-
late AnimationController _controller;
90+
late final CurvedAnimation _animation;
91+
late final AnimationController _controller;
9292
@override
9393
void initState () {
9494
super.initState();
@@ -110,6 +110,7 @@ class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProvi
110110
@override
111111
void dispose() {
112112
_controller.dispose();
113+
_animation.dispose();
113114
super.dispose();
114115
}
115116

packages/flutter/test/material/filter_chip_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:flutter/foundation.dart';
1111
import 'package:flutter/gestures.dart';
1212
import 'package:flutter/material.dart';
1313
import 'package:flutter_test/flutter_test.dart';
14+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1415

1516
import 'feedback_tester.dart';
1617

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

959-
testWidgets('Customize FilterChip delete button', (WidgetTester tester) async {
960+
testWidgets('Customize FilterChip delete button',
961+
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
962+
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: const <String>['CurvedAnimation']),
963+
(WidgetTester tester) async {
960964
Widget buildChip({
961965
Widget? deleteIcon,
962966
Color? deleteIconColor,

packages/flutter/test/material/input_chip_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ library;
1010
import 'package:flutter/gestures.dart';
1111
import 'package:flutter/material.dart';
1212
import 'package:flutter_test/flutter_test.dart';
13+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
1314

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

459-
testWidgets('Delete button tooltip is not shown on disabled InputChip', (WidgetTester tester) async {
460+
testWidgets('Delete button tooltip is not shown on disabled InputChip',
461+
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
462+
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: const <String>['CurvedAnimation']),
463+
(WidgetTester tester) async {
460464
Widget buildChip({ bool enabled = true }) {
461465
return wrapForChip(
462466
child: InputChip(

packages/flutter/test/material/user_accounts_drawer_header_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:flutter/material.dart';
66
import 'package:flutter/rendering.dart';
77
import 'package:flutter_test/flutter_test.dart';
8+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
89
import '../widgets/semantics_tester.dart';
910

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

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

0 commit comments

Comments
 (0)