SearchDelegate should dispose resources. (#133948)

This commit is contained in:
Polina Cherkasova 2023-09-07 11:13:55 -07:00 committed by GitHub
parent 2867b31f5e
commit 0d198c7ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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';
@ -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'));

View File

@ -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(