CupertinoSearchTextField class Null safety

A CupertinoTextField that mimics the look and behavior of UIKit's UISearchTextField.

This control defaults to showing the basic parts of a UISearchTextField, like the 'Search' placeholder, prefix-ed Search icon, and suffix-ed X-Mark icon.

To control the text that is displayed in the text field, use the controller. For example, to set the initial value of the text field, use a controller that already contains some text such as:

class MyPrefilledSearch extends StatefulWidget {
  @override
  _MyPrefilledSearchState createState() => _MyPrefilledSearchState();
}

class _MyPrefilledSearchState extends State<MyPrefilledSearch> {
  late TextEditingController _textController;

  @override
  void initState() {
    super.initState();
    _textController = TextEditingController(text: 'initial text');
  }

  @override
  Widget build(BuildContext context) {
    return CupertinoSearchTextField(controller: _textController);
  }
}

It is recommended to pass a ValueChanged<String> to both onChanged and onSubmitted parameters in order to be notified once the value of the field changes or is submitted by the keyboard:

class MyPrefilledSearch extends StatefulWidget {
  @override
  _MyPrefilledSearchState createState() => _MyPrefilledSearchState();
}

class _MyPrefilledSearchState extends State<MyPrefilledSearch> {
  @override
  Widget build(BuildContext context) {
    return CupertinoSearchTextField(
      onChanged: (value) {
        print("The text has changed to: " + value);
      },
      onSubmitted: (value) {
        print("Submitted text: " + value);
      },
    );
  }
}

Inheritance

Constructors

CupertinoSearchTextField({Key? key, TextEditingController? controller, ValueChanged<String>? onChanged, ValueChanged<String>? onSubmitted, TextStyle? style, String? placeholder, TextStyle? placeholderStyle, BoxDecoration? decoration, Color? backgroundColor, BorderRadius? borderRadius, EdgeInsetsGeometry padding: const EdgeInsetsDirectional.fromSTEB(3.8, 8, 5, 8), Color itemColor: CupertinoColors.secondaryLabel, double itemSize: 20.0, EdgeInsetsGeometry prefixInsets: const EdgeInsetsDirectional.fromSTEB(6, 0, 0, 4), EdgeInsetsGeometry suffixInsets: const EdgeInsetsDirectional.fromSTEB(0, 0, 5, 2), Icon suffixIcon: const Icon(CupertinoIcons.xmark_circle_fill), OverlayVisibilityMode suffixMode: OverlayVisibilityMode.editing, VoidCallback? onSuffixTap, String? restorationId, FocusNode? focusNode})
Creates a CupertinoTextField that mimics the look and behavior of UIKit's UISearchTextField. [...]
const

Properties

backgroundColor Color?
Set the decoration property's background color. [...]
final
borderRadius BorderRadius?
Sets the decoration property's border radius. [...]
final
controller TextEditingController?
Controls the text being edited. [...]
final
decoration BoxDecoration?
Sets the decoration for the text field. [...]
final
focusNode FocusNode?
An optional focus node to use as the focus node for this widget. [...]
final
hashCode int
The hash code for this object. [...]
@nonVirtual, read-only, inherited
itemColor Color
Sets the color for the suffix and prefix icons. [...]
final
itemSize double
Sets the base icon size for the suffix and prefix icons. [...]
final
key Key?
Controls how one widget replaces another widget in the tree. [...]
final, inherited
onChanged ValueChanged<String>?
Invoked upon user input.
final
onSubmitted ValueChanged<String>?
Invoked upon keyboard submission.
final
onSuffixTap VoidCallback?
Sets the X-Mark (suffix) action. [...]
final
padding EdgeInsetsGeometry
Sets the padding insets for the text and placeholder. [...]
final
placeholder String?
A hint placeholder text that appears when the text entry is empty. [...]
final
placeholderStyle TextStyle?
Sets the style of the placeholder of the textfield. [...]
final
prefixInsets EdgeInsetsGeometry
Sets the padding insets for the suffix. [...]
final
restorationId String?
Restoration ID to save and restore the state of the text field. [...]
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
style TextStyle?
Allows changing the style of the text. [...]
final
suffixIcon Icon
Sets the suffix widget's icon. [...]
final
suffixInsets EdgeInsetsGeometry
Sets the padding insets for the prefix. [...]
final
suffixMode OverlayVisibilityMode
Dictates when the X-Mark (suffix) should be visible. [...]
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree. [...]
inherited
createState() State<StatefulWidget>
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. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent 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}) 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. [...]
@nonVirtual, inherited