CNSearchField class
An iOS-style search field that follows Apple HIG best practices.
Apple HIG Best Practices:
- Use descriptive placeholder text (e.g., "Shows, Movies, and More")
- Search immediately as user types (searchImmediately: true)
- Show suggested search terms before or while typing
- Provide scope controls for filtering categories
- Support tokens for filtering by common terms
Example:
CNSearchField(
placeholder: 'Shows, Movies, and More',
showSuggestions: true,
suggestions: ['Popular', 'New Releases', 'Trending'],
scopeOptions: ['All', 'Movies', 'TV Shows', 'Documentaries'],
onSearchChanged: (text) => performSearch(text),
onSuggestionTapped: (suggestion) => searchFor(suggestion),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- CNSearchField
Constructors
-
CNSearchField({Key? key, String placeholder = 'Search', TextEditingController? controller, FocusNode? focusNode, ValueChanged<
String> ? onChanged, ValueChanged<String> ? onSubmitted, ValueChanged<bool> ? onFocusChanged, bool showSuggestions = false, List<String> suggestions = const [], ValueChanged<String> ? onSuggestionTapped, List<String> scopeOptions = const [], int selectedScope = 0, ValueChanged<int> ? onScopeChanged, bool searchImmediately = true, bool showMicButton = false, VoidCallback? onMicPressed, bool autofocus = false}) -
Creates an iOS-style search field.
const
Properties
- autofocus → bool
-
Whether to autofocus the field
final
- controller → TextEditingController?
-
Text editing controller
final
- focusNode → FocusNode?
-
Focus node
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
onChanged
→ ValueChanged<
String> ? -
Called when search text changes
final
-
onFocusChanged
→ ValueChanged<
bool> ? -
Called when focus state changes
final
- onMicPressed → VoidCallback?
-
Called when microphone button is pressed
final
-
onScopeChanged
→ ValueChanged<
int> ? -
Called when scope changes
final
-
onSubmitted
→ ValueChanged<
String> ? -
Called when search is submitted
final
-
onSuggestionTapped
→ ValueChanged<
String> ? -
Called when a suggestion is tapped
final
- placeholder → String
-
Placeholder text describing what can be searched
Use descriptive text like "Shows, Movies, and More" instead of just "Search"
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
scopeOptions
→ List<
String> -
Scope control options (e.g.,
'All', 'Movies', 'TV Shows')final - searchImmediately → bool
-
Whether to search immediately as user types (default: true per Apple HIG)
final
- selectedScope → int
-
Currently selected scope index
final
- showMicButton → bool
-
Whether to show microphone button
final
- showSuggestions → bool
-
Whether to show search suggestions
final
-
suggestions
→ List<
String> -
List of suggested search terms
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< CNSearchField> -
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