Skip to content

Allow search page widget search field hint text and keyboard text input action to be customizable - #28807

Closed
samlythemanly wants to merge 1 commit into
flutter:masterfrom
samlythemanly:master
Closed

samlythemanly wants to merge 1 commit into
flutter:masterfrom
samlythemanly:master

Conversation

@samlythemanly

@samlythemanly samlythemanly commented Mar 3, 2019 •

Copy link
Copy Markdown

Description

Currently, the search page widget's hint text and keyboard text input action are hardcoded to the material localization of 'Search' and the search text input action, respectively. This prevents further customization where search functionality is desired, but the nuance of the action isn't exactly "searching" (e.g. adding a location via Google Maps Places API autocomplete).

Added a getHintText function (that takes in a BuildContext) and a textInputAction field to SearchDelegate. These default to the previous hardcoded attributes that were present in SearchPage.

These changes are purely aesthetic changes; no additional functionality is provided.
All tests still pass.

Related Issues

N/A

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.
  • My PR includes tests for all changed/updated/fixed behaviors (See Test Coverage).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • 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?

@goderbauer goderbauer added framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages labels Mar 4, 2019
@justinmc
justinmc self-requested a review May 1, 2019 17:20

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@somarkoe Thanks for submitting this and sorry for the lack of reviewers. Looks like a simple improvement to make Search a lot more useful, I'm all on board.

Just a discussion below to decide the best way to do this. There was a Linux test failing, but I think it was flaky so I reran it. We'll see.

Comment thread packages/flutter/lib/src/material/search.dart Outdated
@mikuhl-dev

Copy link
Copy Markdown

While you're at it, please do keyboardType: #29983
You don't always search with text.

@justinmc

justinmc commented May 9, 2019

Copy link
Copy Markdown
Contributor

I agree with the idea to add keyboardType to this as well.

Looks like all tests are passing now. @somarkoe are you still available to get this PR in?

@samlythemanly

Copy link
Copy Markdown
Author

Yes! Sorry, been swamped by work and haven't touched the project that deals with this in a while. I'll add the keyboard type request to it as well.

@justinmc

Copy link
Copy Markdown
Contributor

Awesome, thank you @somarkoe. Update the PR when you get a chance and I'll be happy to help you get this in.

@mikuhl-dev

Copy link
Copy Markdown

@justinmc Perhaps will you be able to get #28165 in too? There's so much about the search page that is hard coded and it shouldn't be.

@justinmc

Copy link
Copy Markdown
Contributor

Yeah that one looks straightforward to me. The original reviewer @HansMuller isn't around today but I'll talk it through with him when he's back.

@mikuhl-dev

Copy link
Copy Markdown

Abandoned? :(

@samlythemanly

Copy link
Copy Markdown
Author

Oops, been a while since I've used git.

Reopened and made the relevant changes. Sorry it took so long!

@mikuhl-dev

Copy link
Copy Markdown

😍 merge this ish!

@mikuhl-dev

Copy link
Copy Markdown

Only thing that could be added on is #30388 / #28165 (seems like they are the same 1 line of code)

@justinmc

Copy link
Copy Markdown
Contributor

@somarkoe Thanks for following up and no worries about the delay!

Sorry to drag this out longer, but I realized that this should update the tests as well. This test should probably say "keyboard shows search button by default" now.

Then, could you add a separate test that tests a different textInputAction? Just duplicate that other test and add textInputAction to the TestHomePage parameters.

After that this is good to go and we can merge.

@justinmc

Copy link
Copy Markdown
Contributor

@MichaelPriebe I'll try to see if we can get things moving on those 2 other PRs you referenced.

@mikuhl-dev mikuhl-dev mentioned this pull request Jun 11, 2019
7 of 9 tasks
@mikuhl-dev

Copy link
Copy Markdown

@justinmc how's this going?

@justinmc

justinmc commented Jun 17, 2019 •

Copy link
Copy Markdown
Contributor

Waiting on @somarkoe for the changes mentioned above. Should be quick changes though.

@mikuhl-dev

Copy link
Copy Markdown

@somarkoe come thru

@samlythemanly
samlythemanly force-pushed the master branch 2 times, most recently from e52b10a to 36bb89a Compare June 22, 2019 22:12
@mikuhl-dev

Copy link
Copy Markdown

@justinmc What do you think?

…action, and keyboard text input type to be customizable.

[Description]
Currently, the search page widget's hint text and keyboard text input action are hardcoded to the material localization of 'Search' and the search text input action, respectively, and the text input type defaults to that defined in `TextField`. This prevents further customization where search functionality is desired, but the nuance of the action isn't exactly "searching" (e.g. adding a location via Google Maps Places API autocomplete).

[Changes]
Added `hintText`, `textInputAction`, and `keyboardType` fields to `SearchDelegate`. These default to the previous hardcoded attributes that were present in `SearchPage` (or `null`).

[Testing]
Added a new unit test to cover the new `textInputAction` case (and modified the existing one's name to indicate it's the default behavior).

All existing tests still pass, as well.
@samlythemanly

Copy link
Copy Markdown
Author

I made the fields non-final since apparently overriding fields when a class is extended is no bueno, and this abstract class is one meant to be extended and not implemented (since it has functions with default behaviors).

@mikuhl-dev

Copy link
Copy Markdown

Excited for this, can finally ditch my very hacky extension of the search delegate.

@mikuhl-dev

Copy link
Copy Markdown

@justinmc Is it ready now?

@mikuhl-dev

Copy link
Copy Markdown

Lets get this pull a'mergin'!

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for the delay! I talked to @HansMuller to get some tips for the non-final problem.

/// for another [showSearch] call.
abstract class SearchDelegate<T> {

/// The type of action button to use for the keyboard.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could keep the fields final by using a constructor instead like this:

  const SearchDelegate({
    this.keyboardType,
    this.hintText,
    this.textInputAction = TextInputAction.search,
  });

Then below, make all of the fields final and remove the default assignment from textInputAction.

if (textInputAction != null) {
this.textInputAction = textInputAction;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Then with the change in my other comment, you can user super here:

...
}) : super(
  textInputAction: textInputAction,
);

@mikuhl-dev

Copy link
Copy Markdown

@somarkoe What do you think about the suggestions?

@mikuhl-dev

Copy link
Copy Markdown

@somarkoe Would love to hear what you think about the suggested changes.

@samlythemanly

Copy link
Copy Markdown
Author

So sorry! Was on vacation and now I'm moving 😅

Ill take a look ASAP!

@shihaohong

Copy link
Copy Markdown
Contributor

I'm going to close this since #36409 has been merged. Thank you @somarkoe for your initial work with this!

@shihaohong shihaohong closed this Jul 29, 2019
@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

framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants