A FormField that contains an Input.

This is a convenience widget that simply wraps an Input widget in a FormField. The FormField maintains the current value of the Input so that you don't need to manage it yourself.

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

To see the use of InputFormField, compare these two ways of a implementing a simple two text field form.

Using InputFormField:

String _firstName, _lastName;
GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
...
new Form(
  key: _formKey,
  child: new Row(
    children: <Widget>[
      new InputFormField(
        labelText: 'First Name',
        onSaved: (InputValue value) { _firstName = value.text; }
      ),
      new InputFormField(
        labelText: 'Last Name',
        onSaved: (InputValue value) { _lastName = value.text; }
      ),
      new RaisedButton(
        child: new Text('SUBMIT'),
        // Instead of _formKey.currentState, you could wrap the
        // RaisedButton in a Builder widget to get access to a BuildContext,
        // and use Form.of(context).
        onPressed: () { _formKey.currentState.save(); },
      ),
   )
 )

Using Input directly:

String _firstName, _lastName;
InputValue _firstNameValue = const InputValue();
InputValue _lastNameValue = const InputValue();
...
new Row(
  children: <Widget>[
    new Input(
      value: _firstNameValue,
      labelText: 'First Name',
      onChanged: (InputValue value) { setState( () { _firstNameValue = value; } ); }
    ),
    new Input(
      value: _lastNameValue,
      labelText: 'Last Name',
      onChanged: (InputValue value) { setState( () { _lastNameValue = value; } ); }
    ),
    new RaisedButton(
      child: new Text('SUBMIT'),
      onPressed: () {
        _firstName = _firstNameValue.text;
        _lastName = _lastNameValue.text;
      },
    ),
 )
Inheritance

Constructors

InputFormField({Key key, GlobalKey focusKey, TextInputType keyboardType: TextInputType.text, Icon icon, String labelText, String hintText, TextStyle style, bool hideText: false, bool isDense: false, bool autofocus: false, int maxLines: 1, InputValue initialValue: InputValue.empty, FormFieldSetter<InputValue> onSaved, FormFieldValidator<InputValue> validator })

Properties

autovalidate bool

If true, this form fields will validate and update its error text immediately after every change. Otherwise, you must call FormFieldState.validate to validate. If part of a Form that autovalidates, this value will be ignored.

read-only, inherited
builder FormFieldBuilder<InputValue>

Function that returns the widget representing this form field. It is passed the form field state as input, containing the current value and validation state of this field.

read-only, inherited
hashCode int

Get a hash code for this object.

read-only, inherited
initialValue InputValue

An optional value to initialize the form field to, or null otherwise.

read-only, inherited
key Key

Controls how one widget replaces another widget in the tree.

read-only, inherited
onSaved FormFieldSetter<InputValue>

An optional method to call with the final value when the form is saved via Form.save().

read-only, inherited
runtimeType Type

A representation of the runtime type of the object.

read-only, inherited
validator FormFieldValidator<InputValue>

An optional method that validates an input. Returns an error string to display if the input is invalid, or null otherwise.

read-only, inherited

Operators

operator ==(other) bool

The equality operator.

inherited

Methods

createElement() StatefulElement

Creates a StatefulElement to manage this widget's location in the tree.

inherited
createState() FormFieldState<InputValue>

Creates the mutable state for this widget at a given location in the tree.

inherited
debugFillDescription(List<String> description) → void

Add additional information to the given description for use by toString.

inherited
noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() String

Returns a string representation of this object.

inherited
toStringShort() String

A short, textual description of this widget.

inherited