TextField constructor

const TextField({Key key, TextEditingController controller, FocusNode focusNode, InputDecoration decoration: const InputDecoration(), TextInputType keyboardType, TextInputAction textInputAction, TextCapitalization textCapitalization: TextCapitalization.none, TextStyle style, TextAlign textAlign: TextAlign.start, TextDirection textDirection, 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, Brightness keyboardAppearance, EdgeInsets scrollPadding: const EdgeInsets.all(20.0), bool enableInteractiveSelection: true, GestureTapCallback onTap })

Creates a Material Design text field.

If decoration is non-null (which is the default), the text field requires one of its ancestors to be a Material widget.

To remove the decoration entirely (including the extra padding introduced by the decoration to save space for the labels), set the decoration to null.

The maxLines property can be set to null to remove the restriction on the number of lines. By default, it is one, meaning this is a single-line text field. maxLines must not be zero.

The maxLength property is set to null by default, which means the number of characters allowed in the text field is not restricted. If maxLength is set, a character counter will be displayed below the field, showing how many characters have been entered and how many are allowed unless the value is set to noMaxLength in which case only the current length is displayed.

After maxLength characters have been input, additional input is ignored, unless maxLengthEnforced is set to false. The TextField enforces the length with a LengthLimitingTextInputFormatter, which is evaluated after the supplied inputFormatters, if any. The maxLength value must be either null or greater than zero.

If maxLengthEnforced is set to false, then more than maxLength characters may be entered, and the error counter and divider will switch to the decoration.errorStyle when the limit is exceeded.

The textAlign, autofocus, obscureText, autocorrect, maxLengthEnforced, scrollPadding, maxLines, maxLength, and enableInteractiveSelection arguments must not be null.

See also:

  • maxLength, which discusses the precise meaning of "number of characters" and how it may differ from the intuitive meaning.

Implementation

const TextField({
  Key key,
  this.controller,
  this.focusNode,
  this.decoration = const InputDecoration(),
  TextInputType keyboardType,
  this.textInputAction,
  this.textCapitalization = TextCapitalization.none,
  this.style,
  this.textAlign = TextAlign.start,
  this.textDirection,
  this.autofocus = false,
  this.obscureText = false,
  this.autocorrect = true,
  this.maxLines = 1,
  this.maxLength,
  this.maxLengthEnforced = true,
  this.onChanged,
  this.onEditingComplete,
  this.onSubmitted,
  this.inputFormatters,
  this.enabled,
  this.cursorWidth = 2.0,
  this.cursorRadius,
  this.cursorColor,
  this.keyboardAppearance,
  this.scrollPadding = const EdgeInsets.all(20.0),
  this.enableInteractiveSelection = true,
  this.onTap,
}) : assert(textAlign != null),
     assert(autofocus != null),
     assert(obscureText != null),
     assert(autocorrect != null),
     assert(maxLengthEnforced != null),
     assert(scrollPadding != null),
     assert(maxLines == null || maxLines > 0),
     assert(maxLength == null || maxLength > 0),
     keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
     assert(enableInteractiveSelection != null),
     super(key: key);