BaseSearchBar class
BaseSearchBar - Cross-platform search bar with native iOS support
Uses native iOS UISearchBar via platform channels for iOS - provides authentic iOS search experience with scope bars and advanced keyboard configuration. Uses Material Design SearchBar for Android and other platforms.
*** use cupertino = { forceUseMaterial: true } force use Material search on iOS *** use material = { forceUseCupertino: true } force use native iOS search on Android
Features:
- Native iOS UISearchBar rendering via platform channels
- Material Design SearchBar for Android
- Consistent API across platforms
- Apple HIG compliant search behavior
- Scope bar support for filtering
- Advanced keyboard and input configuration
- Authentic iOS styling and animations
- Cancel button with native iOS behavior
Apple HIG implementation:
- Descriptive placeholder text support
- Search bar styles (default, prominent, minimal)
- Show/hide cancel button behavior
- Voice search button (iOS 14+)
- Proper keyboard types and appearance
- Scope bar for content filtering
Example:
BaseSearchBar(
placeholder: 'Shows, Movies, and More',
showsCancelButton: true,
showsScopeBar: true,
scopeButtonTitles: ['All', 'Movies', 'TV Shows'],
selectedScopeIndex: 0,
onTextChanged: (text) => performSearch(text),
onSearchButtonClicked: (text) => submitSearch(text),
)
Updated: 2024.10.25 - Renamed from BaseCNSearchBar for consistency
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- BaseStatelessWidget
- BaseSearchBar
Constructors
-
BaseSearchBar({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, BaseParam? baseParam}) -
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
- baseParam → BaseParam?
-
Personalization parameters, gets platform parameters first, then mode parameters
finalinherited
- 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
-
beforeBuild(
BuildContext context) → void -
Called before build
inherited
-
beforeBuildByCupertino(
BuildContext context) → void -
Called before buildByCupertino
inherited
-
beforeBuildByCupertinoNative(
BuildContext context) → void -
Called before buildByCupertinoNative (native iOS implementation)
inherited
-
beforeBuildByMaterial(
BuildContext context) → void -
Called before buildByMaterial
inherited
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
inherited
-
buildByCupertino(
BuildContext context) → Widget - build on cupertino mode (Flutter implementation)
-
buildByCupertinoNative(
BuildContext context) → dynamic -
build on cupertino mode with native iOS components (cupertino_native package)
This is called when baseParam.nativeIOS = true
Default implementation falls back to buildByCupertino()
inherited
-
buildByMaterial(
BuildContext context) → Widget - build on material mode
-
commonBuild(
BuildContext context, BaseParam? baseParam) → dynamic -
inherited
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
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
-
getBuildMode(
BaseParam? baseParam) → WidgetBuildMode -
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
-
valueOf(
String key, dynamic value) → dynamic -
inherited
-
valueOfBaseParam(
BaseParam? baseParam, String key, dynamic value) → dynamic -
No reflection available in Dart
First get value from platform, then from mode, finally from value itself
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited