CupertinoTextField class

An iOS-style text field.

A text field lets the user enter text, either with a hardware keyboard or with an onscreen keyboard.

This widget corresponds to both a UITextField and an editable UITextView on iOS.

The text field calls the onChanged callback whenever the user changes the text in the field. If the user indicates that they are done typing in the field (e.g., by pressing a button on the soft keyboard), the text field calls the onSubmitted callback.

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:

Sample code

class MyPrefilledText extends StatefulWidget {
  @override
  _MyPrefilledTextState createState() => _MyPrefilledTextState();
}

class _MyPrefilledTextState extends State<MyPrefilledText> {
  TextEditingController _textController;

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

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

The controller can also control the selection and composing region (and to observe changes to the text, selection, and composing region).

The text field has an overridable decoration that, by default, draws a rounded rectangle border around the text field. If you set the decoration property to null, the decoration will be removed entirely.

See also:

Inheritance

Constructors

CupertinoTextField({Key key, TextEditingController controller, FocusNode focusNode, BoxDecoration decoration: _kDefaultRoundedBorderDecoration, EdgeInsetsGeometry padding: const EdgeInsets.all(6.0), String placeholder, Widget prefix, OverlayVisibilityMode prefixMode: OverlayVisibilityMode.always, Widget suffix, OverlayVisibilityMode suffixMode: OverlayVisibilityMode.always, OverlayVisibilityMode clearButtonMode: OverlayVisibilityMode.never, TextInputType keyboardType, TextInputAction textInputAction, TextCapitalization textCapitalization: TextCapitalization.none, TextStyle style: _kDefaultTextStyle, TextAlign textAlign: TextAlign.start, bool autofocus: false, bool obscureText: false, bool autocorrect: true, int maxLines: 1, int maxLength, bool maxLengthEnforced: true, ValueChanged<String> onChanged, VoidCallback onEditingComplete, ValueChanged<String> onSubmitted, List<TextInputFormatter> inputFormatters, bool enabled, double cursorWidth: 2.0, Radius cursorRadius, Color cursorColor: CupertinoColors.activeBlue, Brightness keyboardAppearance, EdgeInsets scrollPadding: const EdgeInsets.all(20.0) })
Creates an iOS-style text field. [...]
const

Properties

autocorrect bool
Whether to enable autocorrection. [...]
final
autofocus bool
Whether this text field should focus itself if nothing else is already focused. [...]
final
clearButtonMode OverlayVisibilityMode
Show an iOS-style clear button to clear the current text entry. [...]
final
controller TextEditingController
Controls the text being edited. [...]
final
cursorColor Color
The color to use when painting the cursor. [...]
final
cursorRadius Radius
How rounded the corners of the cursor should be. [...]
final
cursorWidth double
How thick the cursor will be. [...]
final
decoration BoxDecoration
Controls the BoxDecoration of the box behind the text input. [...]
final
enabled bool
Disables the text field when false. [...]
final
focusNode FocusNode
Controls whether this widget has keyboard focus. [...]
final
inputFormatters List<TextInputFormatter>
Optional input validation and formatting overrides. [...]
final
keyboardAppearance Brightness
The appearance of the keyboard. [...]
final
keyboardType TextInputType
The type of keyboard to use for editing the text. [...]
final
maxLength int
The maximum number of characters (Unicode scalar values) to allow in the text field. [...]
final
maxLengthEnforced bool
If true, prevents the field from allowing more than maxLength characters. [...]
final
maxLines int
The maximum number of lines for the text to span, wrapping if necessary. [...]
final
obscureText bool
Whether to hide the text being edited (e.g., for passwords). [...]
final
onChanged ValueChanged<String>
Called when the text being edited changes.
final
onEditingComplete VoidCallback
Called when the user submits editable content (e.g., user presses the "done" button on the keyboard). [...]
final
onSubmitted ValueChanged<String>
Called when the user indicates that they are done editing the text in the field.
final
padding EdgeInsetsGeometry
Padding around the text entry area between the prefix and suffix or the clear button when clearButtonMode is not never. [...]
final
placeholder String
A lighter colored placeholder hint that appears on the first line of the text field when the text entry is empty. [...]
final
prefix Widget
An optional Widget to display before the text.
final
prefixMode OverlayVisibilityMode
Controls the visibility of the prefix widget based on the state of text entry when the prefix argument is not null. [...]
final
scrollPadding EdgeInsets
Configures padding to edges surrounding a Scrollable when the Textfield scrolls into view. [...]
final
style TextStyle
The style to use for the text being edited. [...]
final
suffix Widget
An optional Widget to display after the text.
final
suffixMode OverlayVisibilityMode
Controls the visibility of the suffix widget based on the state of text entry when the suffix argument is not null. [...]
final
textAlign TextAlign
How the text should be aligned horizontally. [...]
final
textCapitalization TextCapitalization
Configures how the platform keyboard will select an uppercase or lowercase keyboard. [...]
final
textInputAction TextInputAction
The type of action button to use for the keyboard. [...]
final
hashCode int
The hash code for this object. [...]
read-only, inherited
key Key
Controls how one widget replaces another widget in the tree. [...]
final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

createState() → _CupertinoTextFieldState
Creates the mutable state for this widget at a given location in the tree. [...]
override
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
override
createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree. [...]
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, 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 toStringDeep. [...]
inherited
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns 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 ==(dynamic other) bool
The equality operator. [...]
inherited