Custom input and FormField
So far, we have seen how the Form
and FormField
widgets help with input manipulation and validation. We also know that Flutter comes with a series of input widgets that are FormField
variants containing helper functions such as save
and validate
.
The extensibility and flexibility of Flutter are everywhere in the framework, so creating custom input fields is entirely possible.
Creating custom inputs
Creating a custom input in Flutter is as simple as creating a normal widget and including the methods described earlier. We normally do this by extending the FormField<inputType>
widget, where inputType
is the value type of the input widget.
So, the typical process is as follows:
- Create a custom widget that extends
StatefulWidget
(to keep track of the value) and accepts input from the user by encapsulating another input widget, or by customizing the whole process, such as by using gestures. - Create a widget that extends
FormField
that...