Skip to content

Commit

Permalink
Fix some leaks and add test to test cover remaining in a simple way. …
Browse files Browse the repository at this point in the history
…(#131373)

Contributes to flutter/flutter#130467

Filed issue: flutter/flutter#132620
  • Loading branch information
polina-c authored Aug 16, 2023
1 parent 371a9fc commit 112f429
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ContextMenuController {
/// * [remove], which removes only the current instance.
static void removeAny() {
_menuOverlayEntry?.remove();
_menuOverlayEntry?.dispose();
_menuOverlayEntry = null;
if (_shownInstance != null) {
_shownInstance!.onRemove?.call();
Expand Down
6 changes: 6 additions & 0 deletions packages/flutter/lib/src/widgets/text_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,9 @@ class SelectionOverlay {
void hideHandles() {
if (_handles != null) {
_handles![0].remove();
_handles![0].dispose();
_handles![1].remove();
_handles![1].dispose();
_handles = null;
}
}
Expand Down Expand Up @@ -1480,7 +1482,9 @@ class SelectionOverlay {
_magnifierController.hide();
if (_handles != null) {
_handles![0].remove();
_handles![0].dispose();
_handles![1].remove();
_handles![1].dispose();
_handles = null;
}
if (_toolbar != null || _contextMenuController.isShown || _spellCheckToolbarController.isShown) {
Expand All @@ -1500,6 +1504,7 @@ class SelectionOverlay {
return;
}
_toolbar?.remove();
_toolbar?.dispose();
_toolbar = null;
}

Expand All @@ -1508,6 +1513,7 @@ class SelectionOverlay {
/// {@endtemplate}
void dispose() {
hide();
_magnifierInfo.dispose();
}

Widget _buildStartHandle(BuildContext context) {
Expand Down
34 changes: 34 additions & 0 deletions packages/flutter/test/material/text_form_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,40 @@ void main() {
leakTrackingTestConfig: const LeakTrackingTestConfig(allowAllNotDisposed: true, allowAllNotGCed: true),
);

testWidgetsWithLeakTracking(
'$SelectionOverlay is not leaking',
(WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: 'blah1 blah2',
);
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Center(
child: TextField(
controller: controller,
),
),
),
),
);

final Offset startBlah1 = textOffsetToPosition(tester, 0);
await tester.tapAt(startBlah1);
await tester.pump(const Duration(milliseconds: 100));
await tester.tapAt(startBlah1);
await tester.pumpAndSettle();
await tester.pump();
controller.dispose();
},
skip: kIsWeb, // [intended] we don't supply the cut/copy/paste buttons on the web.
// TODO(polina-c): remove after fixing
// https://github.com/flutter/flutter/issues/132620
leakTrackingTestConfig: const LeakTrackingTestConfig(
notDisposedAllowList: <String, int?>{'_InputBorderGap' : 1},
),
);

testWidgets('the desktop cut/copy/paste buttons are disabled for read-only obscured form fields', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: 'blah1 blah2',
Expand Down

0 comments on commit 112f429

Please sign in to comment.