CupertinoTextField constructor

const CupertinoTextField({Key key, TextEditingController controller, FocusNode focusNode, BoxDecoration decoration: _kDefaultRoundedBorderDecoration, EdgeInsetsGeometry padding: const EdgeInsets.all(6.0), String placeholder, TextStyle placeholderStyle: const TextStyle(fontWeight: FontWeight.w300, color: _kInactiveTextColor), 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, StrutStyle strutStyle, TextAlign textAlign: TextAlign.start, TextAlignVertical textAlignVertical, bool readOnly: false, ToolbarOptions toolbarOptions, bool showCursor, bool autofocus: false, bool obscureText: false, bool autocorrect: true, int maxLines: 1, int minLines, bool expands: false, int maxLength, bool maxLengthEnforced: true, ValueChanged<String> onChanged, VoidCallback onEditingComplete, ValueChanged<String> onSubmitted, List<TextInputFormatter> inputFormatters, bool enabled, double cursorWidth: 2.0, Radius cursorRadius: const Radius.circular(2.0), Color cursorColor, Brightness keyboardAppearance, EdgeInsets scrollPadding: const EdgeInsets.all(20.0), DragStartBehavior dragStartBehavior: DragStartBehavior.start, bool enableInteractiveSelection: true, GestureTapCallback onTap, ScrollController scrollController, ScrollPhysics scrollPhysics })

Creates an iOS-style text field.

To provide a pre-filled text entry, pass in a TextEditingController with an initial value to the controller parameter.

To provide a hint placeholder text that appears when the text entry is empty, pass a String to the placeholder parameter.

The maxLines property can be set to null to remove the restriction on the number of lines. In this mode, the intrinsic height of the widget will grow as the number of lines of text grows. By default, it is 1, meaning this is a single-line text field and will scroll horizontally when overflown. maxLines must not be zero.

The text cursor is not shown if showCursor is false or if showCursor is null (the default) and readOnly is true.

If specified, the maxLength property must be greater than zero.

The autocorrect, autofocus, clearButtonMode, dragStartBehavior, expands, maxLengthEnforced, obscureText, prefixMode, readOnly, scrollPadding, suffixMode, and textAlign properties must not be null.

See also:

  • minLines
  • expands, to allow the widget to size itself to its parent's height.
  • maxLength, which discusses the precise meaning of "number of characters" and how it may differ from the intuitive meaning.

Implementation

const CupertinoTextField({
  Key key,
  this.controller,
  this.focusNode,
  this.decoration = _kDefaultRoundedBorderDecoration,
  this.padding = const EdgeInsets.all(6.0),
  this.placeholder,
  this.placeholderStyle = const TextStyle(
    fontWeight: FontWeight.w300,
    color: _kInactiveTextColor
  ),
  this.prefix,
  this.prefixMode = OverlayVisibilityMode.always,
  this.suffix,
  this.suffixMode = OverlayVisibilityMode.always,
  this.clearButtonMode = OverlayVisibilityMode.never,
  TextInputType keyboardType,
  this.textInputAction,
  this.textCapitalization = TextCapitalization.none,
  this.style,
  this.strutStyle,
  this.textAlign = TextAlign.start,
  this.textAlignVertical,
  this.readOnly = false,
  ToolbarOptions toolbarOptions,
  this.showCursor,
  this.autofocus = false,
  this.obscureText = false,
  this.autocorrect = true,
  this.maxLines = 1,
  this.minLines,
  this.expands = false,
  this.maxLength,
  this.maxLengthEnforced = true,
  this.onChanged,
  this.onEditingComplete,
  this.onSubmitted,
  this.inputFormatters,
  this.enabled,
  this.cursorWidth = 2.0,
  this.cursorRadius = const Radius.circular(2.0),
  this.cursorColor,
  this.keyboardAppearance,
  this.scrollPadding = const EdgeInsets.all(20.0),
  this.dragStartBehavior = DragStartBehavior.start,
  this.enableInteractiveSelection = true,
  this.onTap,
  this.scrollController,
  this.scrollPhysics,
}) : assert(textAlign != null),
     assert(readOnly != null),
     assert(autofocus != null),
     assert(obscureText != null),
     assert(autocorrect != null),
     assert(maxLengthEnforced != null),
     assert(scrollPadding != null),
     assert(dragStartBehavior != null),
     assert(maxLines == null || maxLines > 0),
     assert(minLines == null || minLines > 0),
     assert(
       (maxLines == null) || (minLines == null) || (maxLines >= minLines),
       'minLines can\'t be greater than maxLines',
     ),
     assert(expands != null),
     assert(
       !expands || (maxLines == null && minLines == null),
       'minLines and maxLines must be null when expands is true.',
     ),
     assert(maxLength == null || maxLength > 0),
     assert(clearButtonMode != null),
     assert(prefixMode != null),
     assert(suffixMode != null),
     keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
     toolbarOptions = toolbarOptions ?? obscureText ?
       const ToolbarOptions(
         selectAll: true,
         paste: true,
       ) :
       const ToolbarOptions(
         copy: true,
         cut: true,
         selectAll: true,
         paste: true,
       ),
     super(key: key);