Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between TextFormField and TextField?

Tags:

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?

like image 299
ccc Avatar asked Feb 13 '19 02:02

ccc


People also ask

What is TextFormField in Flutter?

TextFormField widget is used to take input from the user in flutter. This is a simple and easy user input widget in flutter. We can perform any operation on that user input data using TextFormField. You can use that user input, can send and show that input. You can store it into a TextEditingController type object.

What is the difference between a text and a TextField?

The major difference between a textarea and a text field ( ), is that a text field only has one line, whereas a textarea usually has multiple lines.

What does onSaved do in Flutter?

onSaved property Null safetyAn optional method to call with the final value when the form is saved via FormState. save.


Video Answer


1 Answers

If you making a Form where you require save, reset, or validate operations- use TextFormField. Else For Simple user input capture TextField is sufficient.

TextFormField, which integrates with the Form 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:

TextFormField(   autovalidateMode: AutovalidateMode.always   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;   }, ) 

TextField, which is the underlying text field without the Form 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 the onSubmitted callback.

like image 60
anmol.majhail Avatar answered Oct 10 '22 01:10

anmol.majhail