SearchAnchor class

Manages a "search view" route that allows the user to select one of the suggested completions for a search query.

The search view's route can either be shown by creating a SearchController and then calling SearchController.openView or by tapping on an anchor. When the anchor is tapped or SearchController.openView is called, the search view either grows to a specific size, or grows to fill the entire screen. By default, the search view only shows full screen on mobile platforms. Use SearchAnchor.isFullScreen to override the default setting.

The search view is usually opened by a SearchBar, an IconButton or an Icon. If builder returns an Icon, or any un-tappable widgets, we don't have to explicitly call SearchController.openView.

The search view route will be popped if the window size is changed and the search view route is not in full-screen mode. However, if the search view route is in full-screen mode, changing the window size, such as rotating a mobile device from portrait mode to landscape mode, will not close the search view.

This example shows how to use an IconButton to open a search view in a SearchAnchor. It also shows how to use SearchController to open or close the search view route.
link

To create a local project with this code sample, run:
flutter create --sample=material.SearchAnchor.1 mysample

This example shows how to set up a floating (or pinned) AppBar with a SearchAnchor for a title.
link

To create a local project with this code sample, run:
flutter create --sample=material.SearchAnchor.2 mysample

This example shows how to fetch the search suggestions from a remote API.
link

To create a local project with this code sample, run:
flutter create --sample=material.SearchAnchor.3 mysample

This example demonstrates fetching the search suggestions asynchronously and debouncing network calls.
link

To create a local project with this code sample, run:
flutter create --sample=material.SearchAnchor.4 mysample

See also:

  • SearchBar, a widget that defines a search bar.
  • SearchBarTheme, a widget that overrides the default configuration of a search bar.
  • SearchViewTheme, a widget that overrides the default configuration of a search view.
Inheritance

Constructors

SearchAnchor({Key? key, bool? isFullScreen, SearchController? searchController, ViewBuilder? viewBuilder, Widget? viewLeading, Iterable<Widget>? viewTrailing, String? viewHintText, Color? viewBackgroundColor, double? viewElevation, Color? viewSurfaceTintColor, BorderSide? viewSide, OutlinedBorder? viewShape, TextStyle? headerTextStyle, TextStyle? headerHintStyle, Color? dividerColor, BoxConstraints? viewConstraints, TextCapitalization? textCapitalization, ValueChanged<String>? viewOnChanged, ValueChanged<String>? viewOnSubmitted, required SearchAnchorChildBuilder builder, required SuggestionsBuilder suggestionsBuilder, TextInputAction? textInputAction, TextInputType? keyboardType})
Creates a const SearchAnchor.
const
SearchAnchor.bar({Widget? barLeading, Iterable<Widget>? barTrailing, String? barHintText, GestureTapCallback? onTap, ValueChanged<String>? onSubmitted, ValueChanged<String>? onChanged, MaterialStateProperty<double?>? barElevation, MaterialStateProperty<Color?>? barBackgroundColor, MaterialStateProperty<Color?>? barOverlayColor, MaterialStateProperty<BorderSide?>? barSide, MaterialStateProperty<OutlinedBorder?>? barShape, MaterialStateProperty<EdgeInsetsGeometry?>? barPadding, MaterialStateProperty<TextStyle?>? barTextStyle, MaterialStateProperty<TextStyle?>? barHintStyle, Widget? viewLeading, Iterable<Widget>? viewTrailing, String? viewHintText, Color? viewBackgroundColor, double? viewElevation, BorderSide? viewSide, OutlinedBorder? viewShape, TextStyle? viewHeaderTextStyle, TextStyle? viewHeaderHintStyle, Color? dividerColor, BoxConstraints? constraints, BoxConstraints? viewConstraints, bool? isFullScreen, SearchController searchController, TextCapitalization textCapitalization, required SuggestionsBuilder suggestionsBuilder, TextInputAction? textInputAction, TextInputType? keyboardType})
Create a SearchAnchor that has a SearchBar which opens a search view.
factory

Properties

builder SearchAnchorChildBuilder
Called to create a widget which can open a search view route when it is tapped.
final
dividerColor Color?
The color of the divider on the search view.
final
hashCode int
The hash code for this object.
no setterinherited
headerHintStyle TextStyle?
The style to use for the viewHintText on the search view.
final
headerTextStyle TextStyle?
The style to use for the text being edited on the search view.
final
isFullScreen bool?
Whether the search view grows to fill the entire screen when the SearchAnchor is tapped.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
keyboardType TextInputType?
The type of action button to use for the keyboard.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchController SearchController?
An optional controller that allows opening and closing of the search view from other widgets.
final
suggestionsBuilder SuggestionsBuilder
Called to get the suggestion list for the search view.
final
textCapitalization TextCapitalization?
Configures how the platform keyboard will select an uppercase or lowercase keyboard.
final
textInputAction TextInputAction?
The type of action button to use for the keyboard.
final
viewBackgroundColor Color?
The search view's background fill color.
final
viewBuilder ViewBuilder?
Optional callback to obtain a widget to lay out the suggestion list of the search view.
final
viewConstraints BoxConstraints?
Optional size constraints for the search view.
final
viewElevation double?
The elevation of the search view's Material.
final
viewHintText String?
Text that is displayed when the search bar's input field is empty.
final
viewLeading Widget?
An optional widget to display before the text input field when the search view is open.
final
viewOnChanged ValueChanged<String>?
Called each time the user modifies the search view's text field.
final
viewOnSubmitted ValueChanged<String>?
Called when the user indicates that they are done editing the text in the text field of a search view. Typically this is called when the user presses the enter key.
final
viewShape OutlinedBorder?
The shape of the search view's underlying Material.
final
viewSide BorderSide?
The color and weight of the search view's outline.
final
viewSurfaceTintColor Color?
The surface tint color of the search view's Material.
final
viewTrailing Iterable<Widget>?
An optional widget list to display after the text input field when the search view is open.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<SearchAnchor>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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