Unverified Commit 112f4293 authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

Fix some leaks and add test to test cover remaining in a simple way. (#131373)

Contributes to https://github.com/flutter/flutter/issues/130467

Filed issue: https://github.com/flutter/flutter/issues/132620
parent 371a9fc8
...@@ -81,6 +81,7 @@ class ContextMenuController { ...@@ -81,6 +81,7 @@ class ContextMenuController {
/// * [remove], which removes only the current instance. /// * [remove], which removes only the current instance.
static void removeAny() { static void removeAny() {
_menuOverlayEntry?.remove(); _menuOverlayEntry?.remove();
_menuOverlayEntry?.dispose();
_menuOverlayEntry = null; _menuOverlayEntry = null;
if (_shownInstance != null) { if (_shownInstance != null) {
_shownInstance!.onRemove?.call(); _shownInstance!.onRemove?.call();
......
...@@ -1371,7 +1371,9 @@ class SelectionOverlay { ...@@ -1371,7 +1371,9 @@ class SelectionOverlay {
void hideHandles() { void hideHandles() {
if (_handles != null) { if (_handles != null) {
_handles![0].remove(); _handles![0].remove();
_handles![0].dispose();
_handles![1].remove(); _handles![1].remove();
_handles![1].dispose();
_handles = null; _handles = null;
} }
} }
...@@ -1480,7 +1482,9 @@ class SelectionOverlay { ...@@ -1480,7 +1482,9 @@ class SelectionOverlay {
_magnifierController.hide(); _magnifierController.hide();
if (_handles != null) { if (_handles != null) {
_handles![0].remove(); _handles![0].remove();
_handles![0].dispose();
_handles![1].remove(); _handles![1].remove();
_handles![1].dispose();
_handles = null; _handles = null;
} }
if (_toolbar != null || _contextMenuController.isShown || _spellCheckToolbarController.isShown) { if (_toolbar != null || _contextMenuController.isShown || _spellCheckToolbarController.isShown) {
...@@ -1500,6 +1504,7 @@ class SelectionOverlay { ...@@ -1500,6 +1504,7 @@ class SelectionOverlay {
return; return;
} }
_toolbar?.remove(); _toolbar?.remove();
_toolbar?.dispose();
_toolbar = null; _toolbar = null;
} }
...@@ -1508,6 +1513,7 @@ class SelectionOverlay { ...@@ -1508,6 +1513,7 @@ class SelectionOverlay {
/// {@endtemplate} /// {@endtemplate}
void dispose() { void dispose() {
hide(); hide();
_magnifierInfo.dispose();
} }
Widget _buildStartHandle(BuildContext context) { Widget _buildStartHandle(BuildContext context) {
......
...@@ -251,6 +251,40 @@ void main() { ...@@ -251,6 +251,40 @@ void main() {
leakTrackingTestConfig: const LeakTrackingTestConfig(allowAllNotDisposed: true, allowAllNotGCed: true), 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 { testWidgets('the desktop cut/copy/paste buttons are disabled for read-only obscured form fields', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController( final TextEditingController controller = TextEditingController(
text: 'blah1 blah2', text: 'blah1 blah2',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment