Accessing value from a Text Field in Flutter

Using Text Field widget an app can interact with user input. So how do we get the value from the widget ?

There are two ways, one is use change event to store values to a local final variable using SetState of the widget and the second is try using Editing-Controller, which can also offer service like clearing box etc. I go with controller.


Create a text editing controller and attach it to the widget

final mycontroller = TextEditingController();

attach the controller to the widget and it will look like the following

  child: TextField(
                decoration: InputDecoration(hintText: 'Enter todo here'),
 controller: mycontroller,
                onChanged: (value) {},

Using the controller

You can use the controller to access the data and clear the data as follows

              onPressed: () {                
                var newtodo = new Todo(mycontroller.text);               

Flutter Projects


A firebase – Flutter sample application for iOS and Android

Flutter Project Planner

A MongoDB-Flutter cloud application for project management

Hivedb-Flutter Todo

This project store todo items locally using NoSQL database, Hivedb, which is written in dart. Damn blazingly fast

Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

One thought on “Accessing value from a Text Field in Flutter”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.