Skip to content

Commit ef9befc

Browse files
Reland leak fix for EditableTextState (#133806)
Relands: flutter/flutter#131377 Reverted in: flutter/flutter#133804
1 parent 96621eb commit ef9befc

File tree

2 files changed

+7
-27
lines changed

2 files changed

+7
-27
lines changed

packages/flutter/lib/src/widgets/editable_text.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
21252125
late final Simulation _iosBlinkCursorSimulation = _DiscreteKeyFrameSimulation.iOSBlinkingCaret();
21262126

21272127
final ValueNotifier<bool> _cursorVisibilityNotifier = ValueNotifier<bool>(true);
2128+
final ValueNotifier<bool> _debugCursorNotifier = ValueNotifier<bool>(true);
21282129
final GlobalKey _editableKey = GlobalKey();
21292130

21302131
/// Detects whether the clipboard can paste.
@@ -2802,6 +2803,8 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
28022803
void didChangeDependencies() {
28032804
super.didChangeDependencies();
28042805

2806+
_debugCursorNotifier.value = widget.showCursor;
2807+
28052808
_style = MediaQuery.boldTextOf(context)
28062809
? widget.style.merge(const TextStyle(fontWeight: FontWeight.bold))
28072810
: widget.style;
@@ -2956,6 +2959,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
29562959
clipboardStatus.removeListener(_onChangedClipboardStatus);
29572960
clipboardStatus.dispose();
29582961
_cursorVisibilityNotifier.dispose();
2962+
_debugCursorNotifier.dispose();
29592963
FocusManager.instance.removeListener(_unflagInternalFocus);
29602964
super.dispose();
29612965
assert(_batchEditDepth <= 0, 'unfinished batch edits: $_batchEditDepth');
@@ -4857,7 +4861,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
48574861
cursorColor: _cursorColor,
48584862
backgroundCursorColor: widget.backgroundCursorColor,
48594863
showCursor: EditableText.debugDeterministicCursor
4860-
? ValueNotifier<bool>(widget.showCursor)
4864+
? _debugCursorNotifier
48614865
: _cursorVisibilityNotifier,
48624866
forceLine: widget.forceLine,
48634867
readOnly: widget.readOnly,

packages/flutter/test/material/text_selection_theme_test.dart

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,7 @@ void main() {
105105
await tester.pumpAndSettle();
106106
final RenderBox handle = tester.firstRenderObject<RenderBox>(find.byType(CustomPaint));
107107
expect(handle, paints..path(color: defaultSelectionHandleColor));
108-
},
109-
// TODO(polina-c): remove after fixing
110-
// https://github.com/flutter/flutter/issues/130469
111-
leakTrackingTestConfig: const LeakTrackingTestConfig(
112-
notDisposedAllowList: <String, int?>{
113-
'ValueNotifier<MagnifierInfo>': 1,
114-
'ValueNotifier<_OverlayEntryWidgetState?>': 2,
115-
'ValueNotifier<bool>': 2,
116-
'_InputBorderGap': 1,
117-
},
118-
// TODO(polina-c): investigate notGCed, if it does not disappear after fixing notDisposed.
119-
allowAllNotGCed: true,
120-
),
121-
);
108+
});
122109

123110
testWidgetsWithLeakTracking('Material3 - Empty textSelectionTheme will use defaults', (WidgetTester tester) async {
124111
final ThemeData theme = ThemeData(useMaterial3: true);
@@ -167,18 +154,7 @@ void main() {
167154
await tester.pumpAndSettle();
168155
final RenderBox handle = tester.firstRenderObject<RenderBox>(find.byType(CustomPaint));
169156
expect(handle, paints..path(color: defaultSelectionHandleColor));
170-
},
171-
// TODO(polina-c): remove after fixing
172-
// https://github.com/flutter/flutter/issues/130469
173-
leakTrackingTestConfig: const LeakTrackingTestConfig(
174-
notDisposedAllowList: <String, int?>{
175-
'ValueNotifier<MagnifierInfo>': 1,
176-
'ValueNotifier<_OverlayEntryWidgetState?>': 2,
177-
'ValueNotifier<bool>': 2,
178-
'_InputBorderGap': 1,
179-
},
180-
),
181-
);
157+
});
182158

183159
testWidgets('ThemeData.textSelectionTheme will be used if provided', (WidgetTester tester) async {
184160
const TextSelectionThemeData textSelectionTheme = TextSelectionThemeData(

0 commit comments

Comments
 (0)