Fix memory leaks in CupertinoTextMagnifier (#147208)

This commit is contained in:
Valentin Vignal 2024-04-23 13:26:09 +08:00 committed by GitHub
parent 3e8408bb63
commit 1be28aa61a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 8 deletions

View File

@ -82,8 +82,10 @@ class _CupertinoTextMagnifierState extends State<CupertinoTextMagnifier>
// set these values.
Offset _currentAdjustedMagnifierPosition = Offset.zero;
double _verticalFocalPointAdjustment = 0;
late AnimationController _ioAnimationController;
late Animation<double> _ioAnimation;
late final AnimationController _ioAnimationController;
late final Animation<double> _ioAnimation;
late final CurvedAnimation _ioCurvedAnimation;
@override
void initState() {
@ -97,20 +99,21 @@ class _CupertinoTextMagnifierState extends State<CupertinoTextMagnifier>
widget.controller.animationController = _ioAnimationController;
widget.magnifierInfo
.addListener(_determineMagnifierPositionAndFocalPoint);
_ioCurvedAnimation = CurvedAnimation(
parent: _ioAnimationController,
curve: widget.animationCurve,
);
_ioAnimation = Tween<double>(
begin: 0.0,
end: 1.0,
).animate(CurvedAnimation(
parent: _ioAnimationController,
curve: widget.animationCurve,
));
).animate(_ioCurvedAnimation);
}
@override
void dispose() {
widget.controller.animationController = null;
_ioAnimationController.dispose();
_ioCurvedAnimation.dispose();
widget.magnifierInfo
.removeListener(_determineMagnifierPositionAndFocalPoint);
super.dispose();

View File

@ -9,6 +9,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import '../widgets/process_text_utils.dart';
@ -288,7 +289,10 @@ void main() {
expect(content!.plainText, 'How');
});
testWidgets('stopping drag of end handle will show the toolbar', (WidgetTester tester) async {
testWidgets('stopping drag of end handle will show the toolbar',
// 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 {
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);