Skip to content

Conversation

@knaeckeKami
Copy link
Contributor

@knaeckeKami knaeckeKami commented Jul 18, 2019

Description

This fixes issue #18831. A new, optional member "searchFieldLabel" of SearchDelegate was added to specify the label of the search field. If it's specified, it it displayed instead of the default value from DefaultMaterialLocalizations.

Credits to @somarkoe for preparing the addition of some of the added features in #28807

Related Issues

#18831

Tests

I added the following tests:

"Showing custom search hint": a widget test that verifies that the custom search field label is indeed displayed

"Showing default search label if no custom label is given": a widget test that verifies if no searchFieldLabel is specified, the current behaviour of looking up the value from DefaultMaterialLocalizations is unchanged.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jul 18, 2019
@dnfield dnfield requested a review from shihaohong July 22, 2019 21:36
Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few code formatting and API doc suggestions, but otherwise, LGTM

assert(debugCheckHasMaterialLocalizations(context));
final ThemeData theme = widget.delegate.appBarTheme(context);
final String searchFieldLabel = MaterialLocalizations.of(context).searchFieldLabel;
final String searchFieldLabel = widget.delegate.searchFieldLabel ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is more readable:

    final String searchFieldLabel = widget.delegate.searchFieldLabel
      ?? MaterialLocalizations.of(context).searchFieldLabel;

_queryTextController.text = value;
}

/// The hint text to be shown when the search field is empty.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The hint text to be shown when the search field is empty.
/// The hint text that is shown in the search field when it is empty.

Add some documentation to describe what the hint text defaults to if this value is null in another line:
If this value is set to null, the value of MaterialLocalizations.of(context).searchFieldLabel will be used instead.

Also, maybe a code sample for how to use this (as you did with the _TestSearchDelegate in the tests) for other developers.

expect(selectedResults, <String>['Result Foo']);
});

testWidgets('Showing custom search hint', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
testWidgets('Showing custom search hint', (WidgetTester tester) async {
testWidgets('Custom searchFieldLabel value', (WidgetTester tester) async {

testWidgets('Showing custom search hint', (WidgetTester tester) async {
const String searchHint = 'custom search hint';
final String defaultSearchHint =
const DefaultMaterialLocalizations().searchFieldLabel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be in the same line as the previous line

const DefaultMaterialLocalizations().searchFieldLabel;

final _TestSearchDelegate delegate =
_TestSearchDelegate(searchHint: searchHint);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be in the same line as the previous line

expect(find.text(defaultSearchHint), findsNothing);
});

testWidgets('Showing default search label if no custom label is given', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
testWidgets('Showing default search label if no custom label is given', (WidgetTester tester) async {
testWidgets('Default searchFieldLabel is used when it is set to null', (WidgetTester tester) async {


testWidgets('Showing default search label if no custom label is given', (WidgetTester tester) async {
final String searchHint =
const DefaultMaterialLocalizations().searchFieldLabel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be in the same line as the previous line

@knaeckeKami
Copy link
Contributor Author

Thank you for the review, I applied your suggestions.

@shihaohong
Copy link
Contributor

You missed one of the suggestions (search_test.dart L487). Also, you might have to merge your branch with master, one of the presubmit tests are failing, but it seems unlikely to be from your change.

/// @override
/// String get searchFieldLabel => this.searchHint;
///
/// @override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @override
/// @override

///
/// final String searchHint;
///
/// CustomSearchHintDelegate({
Copy link
Contributor

@shihaohong shihaohong Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor should typically be above every other member/method, so just move this above searchHint

///
/// ```dart
/// class CustomSearchHintDelegate extends SearchDelegate {
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for newline here

@shihaohong shihaohong self-assigned this Jul 24, 2019
@knaeckeKami
Copy link
Contributor Author

Yeah, I don't see why my changes would have caused problems specifically on windows. I merged with master and applied the rest of your suggestions.

@shihaohong
Copy link
Contributor

shihaohong commented Jul 24, 2019

It was brought to my attention that this change is related to #28807, except they have some additional functionality, such as keyboard type and the input action.

While I don't necessarily think this should stop your PR if you don't want to include those features, it might be worth looking over some of their comments/discussion and seeing if there is something there that you can apply here, notably suggestions like the one in this comment.

@knaeckeKami
Copy link
Contributor Author

I don't mind adding support for textInputAction and keyboardType. I hope it's not considered rude to "steal" features from another PR, but it seems @somarkoe isn't very responsive in his PR at the moment.

I made searchFieldLabel, keyboardType, and textInputAction final fields the can be set in the constructor. I also find this approach cleaner, albeit maybe little bit less discoverable. I tried to compensate for this by moving the code sample to the constructor.

Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks for doing the additional work of adding the new properties in.

Just a few minor styling suggestions. LGTM

@shihaohong
Copy link
Contributor

I don't mind adding support for textInputAction and keyboardType. I hope it's not considered rude to "steal" features from another PR, but it seems @somarkoe isn't very responsive in his PR at the moment.

I made searchFieldLabel, keyboardType, and textInputAction final fields the can be set in the constructor. I also find this approach cleaner, albeit maybe little bit less discoverable. I tried to compensate for this by moving the code sample to the constructor.

One thing I would definitely do is give @somarkoe credit in the first comment of this PR, something along the lines of this PR.

Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
@samlythemanly
Copy link

I hope it's not considered rude to "steal" features from another PR

Not rude at all! I actually quite appreciate it.

I made the initial PR when I had a endless amounts of free time back in March, but once it actually was pulled into the review process I was swamped in both personal life events as well as work responsibilities and that hasn't really changed!

@knaeckeKami
Copy link
Contributor Author

Applied all suggestions.

@shihaohong shihaohong merged commit 9f08316 into flutter:master Jul 29, 2019
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
…flutter#36409)

* Add searchFieldLabel to SearchDelegate in order to show a custom hint label.

* Add support for specifying textInputAction and keyboardType in SearchDelegate
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants