I am new to Flutter (and Dart) and when trying to build a form to edit an object I searched online for examples and tutorials, and I saw both of these used.
What is the difference between the two? Which one should I use?
flutter
I am new to Flutter (and Dart) and when trying to build a form to edit an object I searched online for examples and tutorials, and I saw both of these used.
What is the difference between the two? Which one should I use?
Best Answer
TextFormField
, which integrates with theForm
widget.This is a convenience widget that wraps a TextField widget in a FormField.
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.
sample:
TextField
, which is the underlying text field without theForm
integration.The text field calls the
onChanged
callback whenever the user changes the text in the field. If the user indicates that they are done typing in the field (e.g., by pressing a button on the soft keyboard), the text field calls theonSubmitted
callback.