Fix leak memory in Tooltip and account detail (#146833)

This commit is contained in:
Valentin Vignal 2024-04-17 03:15:37 +08:00 committed by GitHub
parent c3445dc190
commit 3882afbfa9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 6 deletions

View File

@ -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;
@ -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,
@ -821,6 +828,7 @@ class TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
_tapRecognizer?.dispose();
_timer?.cancel();
_backingController?.dispose();
_backingOverlayAnimation?.dispose();
super.dispose();
}

View File

@ -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();
@ -110,6 +110,7 @@ class _AccountDetailsState extends State<_AccountDetails> with SingleTickerProvi
@override
void dispose() {
_controller.dispose();
_animation.dispose();
super.dispose();
}

View File

@ -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';
@ -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,

View File

@ -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({
@ -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(

View File

@ -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');
@ -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(