From 4b89fce108ac6350b4e73a436f98ba3c3b7d6a74 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Wed, 30 Aug 2023 12:49:56 -0700 Subject: [PATCH] Fixing memory leak in EditableTextState (#131377) --- packages/flutter/lib/src/widgets/editable_text.dart | 5 ++++- .../test/material/text_selection_theme_test.dart | 13 +------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 246b9b7d71..4136c2e7a5 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -2125,6 +2125,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien late final Simulation _iosBlinkCursorSimulation = _DiscreteKeyFrameSimulation.iOSBlinkingCaret(); final ValueNotifier _cursorVisibilityNotifier = ValueNotifier(true); + late final ValueNotifier _debugCursorNotifier; final GlobalKey _editableKey = GlobalKey(); /// Detects whether the clipboard can paste. @@ -2789,6 +2790,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien _scrollController.addListener(_onEditableScroll); _cursorVisibilityNotifier.value = widget.showCursor; _spellCheckConfiguration = _inferSpellCheckConfiguration(widget.spellCheckConfiguration); + _debugCursorNotifier = ValueNotifier(widget.showCursor); } // Whether `TickerMode.of(context)` is true and animations (like blinking the @@ -2933,6 +2935,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien @override void dispose() { + _debugCursorNotifier.dispose(); _internalScrollController?.dispose(); _currentAutofillScope?.unregister(autofillId); widget.controller.removeListener(_didChangeTextEditingValue); @@ -4853,7 +4856,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien cursorColor: _cursorColor, backgroundCursorColor: widget.backgroundCursorColor, showCursor: EditableText.debugDeterministicCursor - ? ValueNotifier(widget.showCursor) + ? _debugCursorNotifier : _cursorVisibilityNotifier, forceLine: widget.forceLine, readOnly: widget.readOnly, diff --git a/packages/flutter/test/material/text_selection_theme_test.dart b/packages/flutter/test/material/text_selection_theme_test.dart index 4a990a5a0a..2e628c5620 100644 --- a/packages/flutter/test/material/text_selection_theme_test.dart +++ b/packages/flutter/test/material/text_selection_theme_test.dart @@ -167,18 +167,7 @@ void main() { await tester.pumpAndSettle(); final RenderBox handle = tester.firstRenderObject(find.byType(CustomPaint)); expect(handle, paints..path(color: defaultSelectionHandleColor)); - }, - // TODO(polina-c): remove after fixing - // https://github.com/flutter/flutter/issues/130469 - leakTrackingTestConfig: const LeakTrackingTestConfig( - notDisposedAllowList: { - 'ValueNotifier': 1, - 'ValueNotifier<_OverlayEntryWidgetState?>': 2, - 'ValueNotifier': 2, - '_InputBorderGap': 1, - }, - ), - ); + }); testWidgets('ThemeData.textSelectionTheme will be used if provided', (WidgetTester tester) async { const TextSelectionThemeData textSelectionTheme = TextSelectionThemeData(