Unverified Commit ee274fde authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `showSearch` query text field doesn't show toolbar initially when field is empty. (#105023)

parent c02be8cd
......@@ -263,7 +263,9 @@ abstract class SearchDelegate<T> {
set query(String value) {
assert(query != null);
_queryTextController.text = value;
_queryTextController.selection = TextSelection.fromPosition(TextPosition(offset: _queryTextController.text.length));
if (_queryTextController.text.isNotEmpty) {
_queryTextController.selection = TextSelection.fromPosition(TextPosition(offset: _queryTextController.text.length));
}
}
/// Transition from the suggestions returned by [buildSuggestions] to the
......
......@@ -883,6 +883,42 @@ void main() {
expect(rootObserver.pushCount, 1);
expect(localObserver.pushCount, 1);
});
testWidgets('Query text field shows toolbar initially', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/95588
final _TestSearchDelegate delegate = _TestSearchDelegate();
final List<String> selectedResults = <String>[];
await tester.pumpWidget(TestHomePage(
delegate: delegate,
results: selectedResults,
));
// Open search.
await tester.tap(find.byTooltip('Search'));
await tester.pumpAndSettle();
final Finder textFieldFinder = find.byType(TextField);
final TextField textField = tester.widget<TextField>(textFieldFinder);
expect(textField.controller!.text.length, 0);
mockClipboard.handleMethodCall(const MethodCall(
'Clipboard.setData',
<String, dynamic>{
'text': 'pasteablestring',
},
));
// Long press shows toolbar.
await tester.longPress(textFieldFinder);
await tester.pump();
expect(find.text('Paste'), findsOneWidget);
await tester.tap(find.text('Paste'));
await tester.pump();
expect(textField.controller!.text.length, 15);
}, skip: kIsWeb); // [intended] We do not use Flutter-rendered context menu on the Web.
}
class TestHomePage extends StatelessWidget {
......
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