From ef9befc9da9f358f301d052e900b36ea3e797565 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Sun, 3 Sep 2023 11:23:20 -0700 Subject: [PATCH] Reland leak fix for EditableTextState (#133806) Relands: https://github.com/flutter/flutter/pull/131377 Reverted in: https://github.com/flutter/flutter/pull/133804 --- .../lib/src/widgets/editable_text.dart | 6 +++- .../material/text_selection_theme_test.dart | 28 ++----------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index afd29530f9..d3e8663271 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); + final ValueNotifier _debugCursorNotifier = ValueNotifier(true); final GlobalKey _editableKey = GlobalKey(); /// Detects whether the clipboard can paste. @@ -2802,6 +2803,8 @@ class EditableTextState extends State with AutomaticKeepAliveClien void didChangeDependencies() { super.didChangeDependencies(); + _debugCursorNotifier.value = widget.showCursor; + _style = MediaQuery.boldTextOf(context) ? widget.style.merge(const TextStyle(fontWeight: FontWeight.bold)) : widget.style; @@ -2956,6 +2959,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien clipboardStatus.removeListener(_onChangedClipboardStatus); clipboardStatus.dispose(); _cursorVisibilityNotifier.dispose(); + _debugCursorNotifier.dispose(); FocusManager.instance.removeListener(_unflagInternalFocus); super.dispose(); assert(_batchEditDepth <= 0, 'unfinished batch edits: $_batchEditDepth'); @@ -4857,7 +4861,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..50553dc297 100644 --- a/packages/flutter/test/material/text_selection_theme_test.dart +++ b/packages/flutter/test/material/text_selection_theme_test.dart @@ -105,20 +105,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, - }, - // TODO(polina-c): investigate notGCed, if it does not disappear after fixing notDisposed. - allowAllNotGCed: true, - ), - ); + }); testWidgetsWithLeakTracking('Material3 - Empty textSelectionTheme will use defaults', (WidgetTester tester) async { final ThemeData theme = ThemeData(useMaterial3: true); @@ -167,18 +154,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(