Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Change search hint text of SearchDelegate

In current implementation of SearchDelegate, there is no option to change the hint text. When the query is empty, search screen is displaying "Search" in the query field as a hint text.

Hint text is currently defined on line 395 as follows:

final String searchFieldLabel = MaterialLocalizations.of(context).searchFieldLabel; 

There is, however, an existing issue to this subject reported.

I wasn't able to come up with any solution for this. Do you know any workaround for the issue?

like image 284
Despotovic Avatar asked Feb 04 '19 14:02

Despotovic


People also ask

How do I customize SearchDelegate flutter?

I found one way to customize flutter search delegate the way you want. you just have to copy flutter's search delegates code and then customize the code you want. Here is the Solution: 1: this is the code of showSearch. Container( padding: EdgeInsets.

How do you change the hint text color in flutter?

You can change hint text color in Flutter, by adding style to the TextField widget. Basically, you provide the styling instructions by using the InputDecoration widget.

How do you use search delegate in flutter?

SearchDelegate<T> class Null safety. Delegate for showSearch to define the content of the search page. The search page always shows an AppBar at the top where users can enter their search queries. The buttons shown before and after the search query text field can be customized via SearchDelegate.

What is showSearch in flutter?

Shows a full screen search page and returns the search result selected by the user when the page is closed. The search page consists of an app bar with a search field and a body which can either show suggested search queries or the search results.


2 Answers

Currently SearchDelegate has an optional member "searchFieldLabel" to specify the label of the search field. It should look something like this:

  @override   String get searchFieldLabel => 'custom label'; 
like image 69
Manassé Avatar answered Sep 23 '22 04:09

Manassé


class SongSearch extends SearchDelegate<String> {   SongSearch({     String hintText = "Song Search",   }) : super(           searchFieldLabel: hintText,           keyboardType: TextInputType.text,           textInputAction: TextInputAction.search,         ); ..... 
like image 25
Rafsan Uddin Beg Rizan Avatar answered Sep 21 '22 04:09

Rafsan Uddin Beg Rizan