show method

Future<void> show({
  1. String placeholder = 'Search',
  2. CNKeyboardType keyboardType = CNKeyboardType.defaultType,
  3. CNKeyboardAppearance keyboardAppearance = CNKeyboardAppearance.defaultAppearance,
  4. CNReturnKeyType returnKeyType = CNReturnKeyType.search,
  5. bool enablesReturnKeyAutomatically = true,
  6. CNAutocapitalizationType autocapitalizationType = CNAutocapitalizationType.none,
  7. CNAutocorrectionType autocorrectionType = CNAutocorrectionType.defaultType,
  8. CNSpellCheckingType spellCheckingType = CNSpellCheckingType.defaultType,
  9. int? barTintColor,
  10. int? tintColor,
  11. int? searchFieldBackgroundColor,
  12. ValueChanged<String>? onTextChanged,
  13. ValueChanged<String>? onSubmitted,
  14. VoidCallback? onCancelled,
})

Shows the native search controller as a modal.

Parameters:

  • placeholder: Placeholder text for the search bar
  • keyboardType: Type of keyboard to display
  • keyboardAppearance: Appearance of the keyboard
  • returnKeyType: Type of return key to display
  • enablesReturnKeyAutomatically: Whether to enable return key automatically
  • autocapitalizationType: Text autocapitalization behavior
  • autocorrectionType: Text autocorrection behavior
  • spellCheckingType: Spell checking behavior
  • barTintColor: Background color of the search bar
  • tintColor: Tint color for search bar elements
  • searchFieldBackgroundColor: Background color of the search text field
  • onTextChanged: Called when search text changes
  • onSubmitted: 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');
  }
}