X

Flutter TextEditingController | Widget of the Day | Controllers

 

Flutter TextEditingController :

Flutter TextEditingController is used fetch the data from TextFormField, with the help of the controller we can access the user input and process accordingly.

You can make use of the listeners and get to know the updated text which user enters into the text fields and can process them accordingly.

The best example you can find in text validations where you can validate the email address, password entered in login screen and enable button click on proper validation.

 

Flutter TextEditingController Video Tutorial :

 

Usage :

There will be a name to be specified for controller to distinguish between several controllers.

TextField(
    controller: emailController,
    obscureText: false,
    decoration: InputDecoration(
        border: InputBorder.none,
        fillColor: Color(0xfff3f3f4),
        filled: true))

 

TextField(
    controller: pwdController,
    obscureText: true,
    decoration: InputDecoration(
        border: InputBorder.none,
        fillColor: Color(0xfff3f3f4),
        filled: true))

 

To fetch the data from controllers

 emailController.text.toString()
 pwdController.text.toString()

And also make sure that you dispose the controllers properly

 @override
 void dispose() {
  emailController.dispose();
  super.dispose();
 }

 

If you have any query’s in this tutorial on flutter TextEditingController let us know in the comment section below.For more interesting flutter tutorials do like and share for more interesting tutorials.

abhishek:
Related Post

This website uses cookies.