_SearchBarState should dispose FocusNode, if it created it. (#134076)

Relanding of revert: https://github.com/flutter/flutter/pull/134072

Verified failed tests succeeded now:
This commit is contained in:
Polina Cherkasova 2023-09-07 16:27:12 -07:00 committed by GitHub
parent 5a8a20c63e
commit 1c0b4ad53a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -1179,6 +1179,9 @@ class _SearchBarState extends State<SearchBar> {
@override
void dispose() {
_internalStatesController.dispose();
if (widget.focusNode == null) {
_focusNode.dispose();
}
super.dispose();
}

View File

@ -6,9 +6,10 @@ import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
testWidgets('SearchBar defaults', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SearchBar defaults', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
final ColorScheme colorScheme = theme.colorScheme;