show method
Future<void>
show({
- String placeholder = 'Search',
- 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,
- int? barTintColor,
- int? tintColor,
- int? searchFieldBackgroundColor,
- ValueChanged<
String> ? onTextChanged, - ValueChanged<
String> ? onSubmitted, - VoidCallback? onCancelled,
Shows the native search controller as a modal.
Parameters:
placeholder: Placeholder text for the search barkeyboardType: Type of keyboard to displaykeyboardAppearance: Appearance of the keyboardreturnKeyType: Type of return key to displayenablesReturnKeyAutomatically: Whether to enable return key automaticallyautocapitalizationType: Text autocapitalization behaviorautocorrectionType: Text autocorrection behaviorspellCheckingType: Spell checking behaviorbarTintColor: Background color of the search bartintColor: Tint color for search bar elementssearchFieldBackgroundColor: Background color of the search text fieldonTextChanged: Called when search text changesonSubmitted: Called when search is submitted (return key pressed)onCancelled: Called when search is cancelled
Implementation
Future<void> show({
String placeholder = 'Search',
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,
int? barTintColor,
int? tintColor,
int? searchFieldBackgroundColor,
ValueChanged<String>? onTextChanged,
ValueChanged<String>? onSubmitted,
VoidCallback? onCancelled,
}) async {
// Setup method call listener for callbacks (only once)
if (!_handlerSetup) {
_setupMethodCallHandler();
_handlerSetup = true;
}
// Store callbacks
_callbacks['onTextChanged'] = onTextChanged;
_callbacks['onSubmitted'] = onSubmitted;
_callbacks['onCancelled'] = onCancelled;
try {
print('[CNNativeSearchController] Calling show() with placeholder: $placeholder');
await platform.invokeMethod('show', {
'placeholder': placeholder,
'keyboardType': keyboardType.index,
'keyboardAppearance': keyboardAppearance.index,
'returnKeyType': returnKeyType.index,
'enablesReturnKeyAutomatically': enablesReturnKeyAutomatically,
'autocapitalizationType': autocapitalizationType.index,
'autocorrectionType': autocorrectionType.index,
'spellCheckingType': spellCheckingType.index,
if (barTintColor != null) 'barTintColor': barTintColor,
if (tintColor != null) 'tintColor': tintColor,
if (searchFieldBackgroundColor != null)
'searchFieldBackgroundColor': searchFieldBackgroundColor,
});
print('[CNNativeSearchController] show() completed successfully');
} catch (e) {
print('[CNNativeSearchController] Error showing search controller: $e');
}
}