Skip to content

Commit

Permalink
SearchDelegate should dispose resources. (#133948)
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c authored Sep 7, 2023
1 parent 2867b31 commit 0d198c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions packages/flutter/lib/src/material/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@ abstract class SearchDelegate<T> {
}

_SearchPageRoute<T>? _route;

/// Releases the resources.
@mustCallSuper
void dispose() {
_currentBodyNotifier.dispose();
_focusNode?.dispose();
_queryTextController.dispose();
_proxyAnimation.parent = null;
}
}

/// Describes the body that is currently shown under the [AppBar] in the
Expand Down
4 changes: 3 additions & 1 deletion packages/flutter/test/material/search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

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

testWidgets('Changing query moves cursor to the end of query', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Changing query moves cursor to the end of query', (WidgetTester tester) async {
final _TestSearchDelegate delegate = _TestSearchDelegate();
addTearDown(() => delegate.dispose());

await tester.pumpWidget(TestHomePage(delegate: delegate));
await tester.tap(find.byTooltip('Search'));
Expand Down
4 changes: 1 addition & 3 deletions packages/flutter/test/material/segmented_button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ Widget boilerplate({required Widget child}) {

void main() {

testWidgetsWithLeakTracking('SegmentedButton is built with Material of type MaterialType.transparency',
leakTrackingTestConfig: LeakTrackingTestConfig.debugNotDisposed(),
(WidgetTester tester) async {
testWidgetsWithLeakTracking('SegmentedButton is built with Material of type MaterialType.transparency', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(
MaterialApp(
Expand Down

0 comments on commit 0d198c7

Please sign in to comment.