Skip to content

Commit

Permalink
Fix showSearch query text field doesn't show toolbar initially when…
Browse files Browse the repository at this point in the history
… field is empty. (#105023)
  • Loading branch information
TahaTesser authored May 31, 2022
1 parent c02be8c commit ee274fd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/flutter/lib/src/material/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions packages/flutter/test/material/search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ee274fd

Please sign in to comment.