SearchDelegate<T> class abstract

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.buildLeading and SearchDelegate.buildActions. Additionally, a widget can be placed across the bottom of the AppBar via SearchDelegate.buildBottom.

The body below the AppBar can either show suggested queries (returned by SearchDelegate.buildSuggestions) or - once the user submits a search - the results of the search as returned by SearchDelegate.buildResults.

SearchDelegate.query always contains the current query entered by the user and should be used to build the suggestions and results.

The results can be brought on screen by calling SearchDelegate.showResults and you can go back to showing the suggestions by calling SearchDelegate.showSuggestions.

Once the user has selected a search result, SearchDelegate.close should be called to remove the search page from the top of the navigation stack and to notify the caller of showSearch about the selected search result.

A given SearchDelegate can only be associated with one active showSearch call. Call SearchDelegate.close before re-using the same delegate instance for another showSearch call.

Handling emojis and other complex characters

It's important to always use characters when dealing with user input text that may contain complex characters. This will ensure that extended grapheme clusters and surrogate pairs are treated as single characters, as they appear to the user.

For example, when finding the length of some user input, use string.characters.length. Do NOT use string.length or even string.runes.length. For the complex character "👨‍👩‍👦", this appears to the user as a single character, and string.characters.length intuitively returns 1. On the other hand, string.length returns 8, and string.runes.length returns 5!

Constructors

SearchDelegate({String? searchFieldLabel, TextStyle? searchFieldStyle, InputDecorationTheme? searchFieldDecorationTheme, TextInputType? keyboardType, TextInputAction textInputAction = TextInputAction.search})
Constructor to be called by subclasses which may specify searchFieldLabel, either searchFieldStyle or searchFieldDecorationTheme, keyboardType and/or textInputAction. Only one of searchFieldLabel and searchFieldDecorationTheme may be non-null.

Properties

automaticallyImplyLeading bool?
Controls whether we should try to imply the leading widget if null.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
keyboardType TextInputType?
The type of action button to use for the keyboard.
final
leadingWidth double?
Defines the width of AppBar.leading widget.
getter/setter pair
query String
The current query string shown in the AppBar.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchFieldDecorationTheme InputDecorationTheme?
The InputDecorationTheme used to configure the search field's visuals.
final
searchFieldLabel String?
The hint text that is shown in the search field when it is empty.
final
searchFieldStyle TextStyle?
The style of the searchFieldLabel.
final
textInputAction TextInputAction
The text input action configuring the soft keyboard to a particular action button.
final
transitionAnimation Animation<double>
Animation triggered when the search pages fades in or out.
no setter

Methods

appBarTheme(BuildContext context) ThemeData
The theme used to configure the search page.
buildActions(BuildContext context) List<Widget>?
Widgets to display after the search query in the AppBar.
buildBottom(BuildContext context) PreferredSizeWidget?
Widget to display across the bottom of the AppBar.
buildFlexibleSpace(BuildContext context) Widget?
Widget to display a flexible space in the AppBar.
buildLeading(BuildContext context) Widget?
A widget to display before the current query in the AppBar.
buildResults(BuildContext context) Widget
The results shown after the user submits a search from the search page.
buildSuggestions(BuildContext context) Widget
Suggestions shown in the body of the search page while the user types a query into the search field.
close(BuildContext context, T result) → void
Closes the search page and returns to the underlying route.
dispose() → void
Releases the resources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
showResults(BuildContext context) → void
Transition from the suggestions returned by buildSuggestions to the query results returned by buildResults.
showSuggestions(BuildContext context) → void
Transition from showing the results returned by buildResults to showing the suggestions returned by buildSuggestions.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited