showSearch<T> function

Future<T> showSearch <T>({@required BuildContext context, @required SearchDelegate<T> delegate, String query: '' })

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.

The appearance of the search page is determined by the provided delegate. The initial query string is given by query, which defaults to the empty string. When query is set to null, delegate.query will be used as the initial query.

The method returns the selected search result, which can be set in the SearchDelegate.close call.

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.

The transition to the search page triggered by this method looks best if the screen triggering the transition contains an AppBar at the top and the transition is called from an IconButton that's part of AppBar.actions. The animation provided by SearchDelegate.transitionAnimation can be used to trigger additional animations in the underlying page while the search page fades in or out. This is commonly used to animate an AnimatedIcon in the AppBar.leading position e.g. from the hamburger menu to the back arrow used to exit the search page.

See also:


Future<T> showSearch<T>({
  @required BuildContext context,
  @required SearchDelegate<T> delegate,
  String query: '',
}) {
  assert(delegate != null);
  assert(context != null);
  assert(delegate._result == null || delegate._result.isCompleted);
  delegate._result = new Completer<T>();
  delegate.query = query ?? delegate.query;
  delegate._currentBody = _SearchBody.suggestions;
  Navigator.of(context).push(new _SearchPageRoute<T>(
    delegate: delegate,
  return delegate._result.future;