Skip to content

Commit 0d198c7

Browse files
authored
SearchDelegate should dispose resources. (#133948)
1 parent 2867b31 commit 0d198c7

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/flutter/lib/src/material/search.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,15 @@ abstract class SearchDelegate<T> {
377377
}
378378

379379
_SearchPageRoute<T>? _route;
380+
381+
/// Releases the resources.
382+
@mustCallSuper
383+
void dispose() {
384+
_currentBodyNotifier.dispose();
385+
_focusNode?.dispose();
386+
_queryTextController.dispose();
387+
_proxyAnimation.parent = null;
388+
}
380389
}
381390

382391
/// Describes the body that is currently shown under the [AppBar] in the

packages/flutter/test/material/search_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
66
import 'package:flutter/material.dart';
77
import 'package:flutter/services.dart';
88
import 'package:flutter_test/flutter_test.dart';
9+
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
910

1011
import '../widgets/clipboard_utils.dart';
1112
import '../widgets/semantics_tester.dart';
@@ -25,8 +26,9 @@ void main() {
2526
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, null);
2627
});
2728

28-
testWidgets('Changing query moves cursor to the end of query', (WidgetTester tester) async {
29+
testWidgetsWithLeakTracking('Changing query moves cursor to the end of query', (WidgetTester tester) async {
2930
final _TestSearchDelegate delegate = _TestSearchDelegate();
31+
addTearDown(() => delegate.dispose());
3032

3133
await tester.pumpWidget(TestHomePage(delegate: delegate));
3234
await tester.tap(find.byTooltip('Search'));

packages/flutter/test/material/segmented_button_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ Widget boilerplate({required Widget child}) {
2222

2323
void main() {
2424

25-
testWidgetsWithLeakTracking('SegmentedButton is built with Material of type MaterialType.transparency',
26-
leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed(),
27-
(WidgetTester tester) async {
25+
testWidgetsWithLeakTracking('SegmentedButton is built with Material of type MaterialType.transparency', (WidgetTester tester) async {
2826
final ThemeData theme = ThemeData(useMaterial3: true);
2927
await tester.pumpWidget(
3028
MaterialApp(

0 commit comments

Comments
 (0)