GlassSearchBar class Panels and controls
A search field in a glass capsule, with a clear button while there is text and a Cancel button that slides in beside it while it has the focus.
The field is GlassTextField.search: a magnifier, "Search" while empty, and the keyboard's search action. The clear button — a filled circle with a cross, inside the glass at the field's end — appears while there is text and empties the field, keeping the focus. Cancel, when showsCancelButton, slides in over cancelDuration as the field takes the focus; a tap empties the field, lets go of the focus and calls onCancel.
GlassSearchBar(
onChanged: (String query) => setState(() => filter = query),
onSubmitted: runSearch,
onCancel: () => setState(() => filter = ''),
)
Note: one surface, the field's. Typing and the clear button are no capture. Cancel is plain text in cancelColor, beside the glass rather than on it, as iOS draws it — but its slide narrows the glass, and a glass whose box changes is retaken: a capture a frame for cancelDuration on focus and on blur, none under reduced motion.
See also:
- GlassTextField, the field underneath, for a field that is not search.
- GlassBar, which can carry the bar at the top of a screen.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- GlassSearchBar
Constructors
-
GlassSearchBar({TextEditingController? controller, FocusNode? focusNode, String placeholder = 'Search', ValueChanged<
String> ? onChanged, ValueChanged<String> ? onSubmitted, VoidCallback? onCancel, bool showsCancelButton = true, String cancelLabel = 'Cancel', Color cancelColor = const Color(0xFF007AFF), Duration cancelDuration = const Duration(milliseconds: 250), bool autofocus = false, GlassFinish? finish, Key? key}) -
A search bar.
controllerandfocusNodeare made and disposed by the bar when null; pass your own to read or set the query or the focus.const
Properties
- autofocus → bool
-
Whether the field takes the focus as soon as it is built.
final
- cancelColor → Color
-
Cancel's colour, and the caret's: iOS's blue by default.
final
- cancelDuration → Duration
-
How long Cancel takes to slide in or out. Zero under reduced motion
whatever is passed.
final
- cancelLabel → String
-
Cancel's text. "Cancel" by default; pass the localized word.
final
- controller → TextEditingController?
-
The query. Null makes one the bar owns and disposes.
final
- finish → GlassFinish?
-
The optics of the field's glass. Null takes the theme's.
final
- focusNode → FocusNode?
-
The field's focus. Null makes one the bar owns and disposes.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- onCancel → VoidCallback?
-
Called when Cancel is tapped, after the field is emptied and has let go
of the focus.
final
-
onChanged
→ ValueChanged<
String> ? -
Called with the whole query on every edit, and with
''when the clear button or Cancel empties it.final -
onSubmitted
→ ValueChanged<
String> ? -
Called with the query when the keyboard's search action is pressed.
final
- placeholder → String
-
Shown, dimmed, while the field is empty.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showsCancelButton → bool
-
Whether Cancel slides in while the field has the focus. On by default,
as on an iPhone; iOS ignores it on an iPad.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< GlassSearchBar> -
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.
override
-
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, int wrapWidth = 65}) → 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