GlassSearchBar class

A glass morphism search bar following Apple's iOS 26 design patterns.

GlassSearchBar provides a sophisticated search field with pill shape, animated clear button, and optional cancel button that slides in from the right. It matches iOS's UISearchBar appearance and behavior with glass morphism effects.

Key Features

  • Pill-Shaped Glass: Rounded search field with glass effect
  • Animated Clear Button: Appears/fades when text is entered
  • Cancel Button: Optional slide-in cancel button (iOS pattern)
  • Search Icon: Leading search icon with customizable color
  • Auto-focus Support: Can auto-focus on appearance
  • Dual Mode: Grouped or standalone rendering

Usage

Basic Usage

String query = '';

GlassSearchBar(
  placeholder: 'Search',
  onChanged: (value) {
    setState(() => query = value);
  },
)

With Cancel Button

GlassSearchBar(
  placeholder: 'Search messages',
  showsCancelButton: true,
  onCancel: () {
    // Clear search and dismiss keyboard
  },
)

Within LiquidGlassLayer (Grouped Mode)

AdaptiveLiquidGlassLayer(
  settings: LiquidGlassSettings(
    thickness: 30,
    blur: 8,
    refractiveIndex: 1.59,
  ),
  child: Column(
    children: [
      GlassSearchBar(
        placeholder: 'Search',
        onChanged: (value) => _performSearch(value),
      ),
      // Search results...
    ],
  ),
)

Standalone Mode

GlassSearchBar(
  placeholder: 'Search',
  useOwnLayer: true,
  settings: LiquidGlassSettings(
    thickness: 30,
    blur: 8,
  ),
  onChanged: (value) => _performSearch(value),
)

Custom Styling

GlassSearchBar(
  placeholder: 'Search products...',
  searchIconColor: Colors.blue,
  clearIconColor: Colors.blue,
  cancelButtonColor: Colors.blue,
  textStyle: TextStyle(fontSize: 18, color: Colors.white),
  height: 48,
)
Inheritance

Constructors

GlassSearchBar({Key? key, TextEditingController? controller, FocusNode? focusNode, String placeholder = 'Search', ValueChanged<String>? onChanged, ValueChanged<String>? onSubmitted, VoidCallback? onCancel, bool showsCancelButton = false, bool autofocus = false, bool enabled = true, Color? searchIconColor, Color? clearIconColor, Color? cancelButtonColor, Widget? cancelIcon, double cancelIconSize = 24, TextStyle? textStyle, TextStyle? placeholderStyle, double height = 44.0, LiquidGlassSettings? settings, bool useOwnLayer = false, GlassQuality? quality, String? clearButtonSemanticLabel, String? cancelButtonSemanticLabel})
Creates a glass search bar.
const

Properties

autofocus → bool
Whether the search field should auto-focus.
final
cancelButtonColor → Color?
Color of the cancel (×) icon.
final
cancelButtonSemanticLabel → String?
Screen reader label of the cancel button beside the field.
final
cancelIcon → Widget?
Custom icon widget for the cancel button.
final
cancelIconSize → double
Size of the cancel (×) icon in logical pixels.
final
clearButtonSemanticLabel → String?
Screen reader label of the clear (×) button inside the field.
final
clearIconColor → Color?
Color of the clear button icon.
final
controller → TextEditingController?
Controls the text being edited.
final
enabled → bool
Whether the search field is enabled.
final
focusNode → FocusNode?
Optional focus node for the search field.
final
hashCode → int
The hash code for this object.
no setterinherited
height → double
Height of the search bar.
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onCancel → VoidCallback?
Called when the cancel button is tapped.
final
onChanged → ValueChanged<String>?
Called when the search text changes.
final
onSubmitted → ValueChanged<String>?
Called when the user submits the search.
final
placeholder → String
Placeholder text shown when the field is empty.
final
placeholderStyle → TextStyle?
The style of the placeholder text.
final
quality → GlassQuality?
Rendering quality for the glass effect.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
searchIconColor → Color?
Color of the search icon.
final
settings → LiquidGlassSettings?
Glass effect settings (only used when useOwnLayer is true).
final
showsCancelButton → bool
Whether to show the cancel button.
final
textStyle → TextStyle?
The style of the search text.
final
useOwnLayer → bool
Whether to create its own layer or use grouped glass.
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.
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, 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