This will be mainly focused around TextField() which is a flutter widget to capture users input. 

 

how do you create TextField?

TextField(decoration: InputDecoration(labelText: 'Title')) 

decoration is optional of course, but in decoration you can specify placeholder for your input.

 

How to capture data from TextField()? 

There are two ways of doing this either by onChanged() method provided in textField or using a controller parameter provided by TextField().

 

Take the following TextFields: 

  String titleInput;
  final amountInputController = TextEditingController();

 

Column(
                children: [
                  TextField(
                    decoration: InputDecoration(labelText: 'Title'),
                    onChanged: (value) => titleInput = value,
                  ),
                  TextField(
                    decoration: InputDecoration(labelText: 'Amount'),
                    controller: amountInputController,
                  ),
                  FlatButton(
                      onPressed: () {
                        print(titleInput);
                        print(amountInputController.text);
                      },
                      child: Text('Add Transaction')),
                ],
              ),

 

The first TextField uses onChanged() which takes a function and the function needs to have a parameter of type String, this parameter is the TextField input and it will be updated every time the user presses the keystroke.

 

The second TextField is using the controller to capture the values and the controller accepts TextEditingController() type which I have defined above for my amountInputController, this will automatically update the variable every time user changes the value in the TextField.