CNSearchBar class

A native iOS UISearchBar widget.

This widget displays a native iOS UISearchBar using platform channels, providing authentic iOS search experience following Apple HIG guidelines.

Features:

  • Native UISearchBar rendering
  • Descriptive placeholder text support
  • Search bar styles (default, prominent, minimal)
  • Scope bar for filtering
  • Show/hide cancel button
  • Keyboard types and appearance
  • Return key types
  • Voice search button (iOS 14+)

Example:

CNSearchBar(
  placeholder: 'Shows, Movies, and More',
  showsCancelButton: true,
  showsScopeBar: true,
  scopeButtonTitles: ['All', 'Movies', 'TV Shows'],
  selectedScopeIndex: 0,
  onTextChanged: (text) => performSearch(text),
  onSearchButtonClicked: (text) => submitSearch(text),
)
Inheritance

Constructors

CNSearchBar({Key? key, String? placeholder, String? text, String? prompt, bool showsCancelButton = false, bool showsBookmarkButton = false, bool showsSearchResultsButton = false, CNSearchBarStyle searchBarStyle = CNSearchBarStyle.defaultStyle, Color? barTintColor, Color? tintColor, Color? searchFieldBackgroundColor, bool showsScopeBar = false, List<String> scopeButtonTitles = const [], int selectedScopeIndex = 0, CNKeyboardType keyboardType = CNKeyboardType.defaultType, CNKeyboardAppearance keyboardAppearance = CNKeyboardAppearance.defaultAppearance, CNReturnKeyType returnKeyType = CNReturnKeyType.search, bool enablesReturnKeyAutomatically = true, CNAutocapitalizationType autocapitalizationType = CNAutocapitalizationType.none, CNAutocorrectionType autocorrectionType = CNAutocorrectionType.defaultType, CNSpellCheckingType spellCheckingType = CNSpellCheckingType.defaultType, ValueChanged<String>? onTextChanged, ValueChanged<String>? onSearchButtonClicked, VoidCallback? onCancelButtonClicked, ValueChanged<int>? onScopeChanged, VoidCallback? onBookmarkButtonClicked, double height = 56.0})
Creates a native iOS search bar.
const

Properties

autocapitalizationType CNAutocapitalizationType
Auto-capitalization behavior
final
autocorrectionType CNAutocorrectionType
Auto-correction behavior
final
barTintColor Color?
Background tint color for the search bar
final
enablesReturnKeyAutomatically bool
Whether return key is enabled only when there's text
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
keyboardAppearance CNKeyboardAppearance
Keyboard appearance (light/dark)
final
keyboardType CNKeyboardType
Keyboard type
final
onBookmarkButtonClicked VoidCallback?
Called when bookmark button is clicked
final
onCancelButtonClicked VoidCallback?
Called when cancel button is clicked
final
onScopeChanged ValueChanged<int>?
Called when scope selection changes
final
onSearchButtonClicked ValueChanged<String>?
Called when search button is clicked
final
onTextChanged ValueChanged<String>?
Called when search text changes
final
placeholder String?
Placeholder text (e.g., "Shows, Movies, and More")
final
prompt String?
Prompt text displayed above the search bar
final
returnKeyType CNReturnKeyType
Return key type
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scopeButtonTitles List<String>
Titles for scope bar buttons
final
searchBarStyle CNSearchBarStyle
Visual style of the search bar
final
searchFieldBackgroundColor Color?
Background color for the search text field
final
selectedScopeIndex int
Selected scope bar index
final
showsBookmarkButton bool
Whether to show the bookmark button
final
showsCancelButton bool
Whether to show the cancel button
final
showsScopeBar bool
Whether to show the scope bar
final
showsSearchResultsButton bool
Whether to show the search results button
final
spellCheckingType CNSpellCheckingType
Spell checking behavior
final
text String?
Initial search text
final
tintColor Color?
Tint color for search bar elements
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<CNSearchBar>
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