InputText class

An InputField that contains a TextField.

This is a convenience widget that wraps a TextField widget in an InputField.

An InputForm ancestor is not required. The InputForm simply makes it easier to enable, save, reset, or validate multiple fields at once. To use without an InputForm, pass a GlobalKey to the constructor and use GlobalKey.currentState to save or reset the form field.

When a controller is specified, its TextEditingController.text defines the initialValue. If this FormField is part of a scrolling container that lazily constructs its children, like a ListView or a CustomScrollView, then a controller should be specified. The controller's lifetime should be managed by a stateful widget ancestor of the scrolling container.

If a controller is not specified, initialValue can be used to give the automatically generated controller an initial value.

Remember to dispose of the TextEditingController when it is no longer needed. This will ensure we discard any resources used by the object.

For a documentation about the various parameters, see TextField.

{@tool sample}

Creates a TextFormField with an InputDecoration and validator function.

If the user enters valid text, the TextField appears normally without any warnings to the user

If the user enters invalid text, the error message returned from the validator function is displayed in dark red underneath the input

TextFormField(
  decoration: const InputDecoration(
    icon: Icon(Icons.person),
    hintText: 'What do people call you?',
    labelText: 'Name *',
  ),
  onSaved: (String value) {
    // This optional block of code can be used to run
    // code when the user saves the form.
  },
  validator: (String value) {
    return value.contains('@') ? 'Do not use the @ char.' : null;
  },
)

{@end-tool}

See also:

Inheritance
Annotations
  • @Deprecated('Please use InputKeyboard<String> instead. Deprecated since v0.2.0.')

Constructors

InputText({Key key, bool autocorrect: true, bool autofocus: false, bool autovalidate: false, InputCounterWidgetBuilder buildCounter, TextEditingController controller, Color cursorColor, Radius cursorRadius, double cursorWidth: 2.0, InputDecoration decoration, bool enabled, bool enableInteractiveSelection: true, bool enableSuggestions: true, bool expands: false, FocusNode focusNode, String initialValue, List<TextInputFormatter> inputFormatters, Brightness keyboardAppearance, TextInputType keyboardType, int maxLength, bool maxLengthEnforced: true, int maxLines: 1, int minLines, bool obscureText: false, ValueChanged<String> onChanged, VoidCallback onEditingComplete, ValueChanged<String> onFieldSubmitted, InputFieldSetter<String> onSaved, GestureTapCallback onTap, String path, bool readOnly: false, bool showCursor, EdgeInsets scrollPadding: const EdgeInsets.all(20.0), StrutStyle strutStyle, TextStyle style, TextAlign textAlign: TextAlign.start, TextAlignVertical textAlignVertical, TextCapitalization textCapitalization: TextCapitalization.none, TextDirection textDirection, TextInputAction textInputAction, ToolbarOptions toolbarOptions, List<InputValidator> validators})
Creates an InputField that contains a TextField. [...]

Properties

autocorrect bool
final
autofocus bool
final
autosave bool
Automatically saves a changed value. If autovalidate is true then a changed value will only be saved if there is no validation failure. Also invokes method onSaved. Default is true.
final, inherited
autovalidate bool
Automatically validates any change and updates error text accordingly. Default is false.
final, inherited
buildCounter InputCounterWidgetBuilder
final
controller TextEditingController
Controls the text being edited. [...]
final
cursorColor Color
final
cursorRadius Radius
final
cursorWidth double
final
decoration InputDecoration
Decoration for the input field supplying frame, label, error text, ...
final, inherited
enabled bool
Whether the field accepts user input. Default is true.
final, inherited
enableInteractiveSelection bool
final
enableSuggestions bool
final
expands bool
final
focusNode FocusNode
final
hashCode int
The hash code for this object. [...]
@nonVirtual, read-only, inherited
initialValue String
The fields value will initially be set to this initialValue.
final, inherited
inputFormatters List<TextInputFormatter>
final
key Key
Controls how one widget replaces another widget in the tree. [...]
final, inherited
keyboardAppearance Brightness
final
keyboardType TextInputType
final
map Map<String, dynamic>
map is used together with path to provide the initial value from and to save changes to the map. This parameter supersedes parameter map given to an InputForm ancestor.
final, inherited
maxLength int
final
maxLengthEnforced bool
final
maxLines int
final
minLines int
final
obscureText bool
final
onChanged ValueSetter<String>
An optional method to call on every change of the fields value.
final, inherited
onEditingComplete VoidCallback
final
onFieldSubmitted ValueChanged<String>
final
onSaved ValueSetter<String>
An optional method to call with the final value when the form is saved through InputFormState.save().
final, inherited
onTap GestureTapCallback
final
path String
The path to the fields value in map. If the form is nested then path elements must be dot separated.
final, inherited
readOnly bool
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
scrollPadding EdgeInsets
final
showCursor bool
final
strutStyle StrutStyle
final
style TextStyle
final
textAlign TextAlign
final
textAlignVertical TextAlignVertical
final
textCapitalization TextCapitalization
final
textDirection TextDirection
final
textInputAction TextInputAction
final
toolbarOptions ToolbarOptions
final
validators List<InputValidator>
Methods that validate an input. The first failed validation will return an error string and no more validations will happen. [...]
final, inherited
wantKeepAlive bool
true will keep the state of all input fields within the same Slider even when the widget is scrolled out of view.
final, inherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree. [...]
inherited
createState() → _InputTextState
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
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 ==(Object other) bool
The equality operator. [...]
@nonVirtual, inherited