mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix showSearch query text field doesn't show toolbar initially when field is empty. (#105023)
This commit is contained in:
parent
c02be8cd47
commit
ee274fde1d
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user