Supply an onChanged() callback to a TextField or a TextFormField.

Use a TextEditingController.

1. Supply an onChanged() callback to a TextField or a TextFormField

The simplest approach is to supply an onChanged() callback to a
TextField or a TextFormField.
Whenever the text changes, the callback is invoked.

In this example, print the current value of the text field to the
console every time the text changes.

2. Use a TextEditingController

A more powerful, but more elaborate approach, is to supply a
TextEditingController as the controller
property of the TextField or a TextFormField.

To be notified when the text changes, listen to the controller
using the addListener() method using the following steps:

Create a TextEditingController.

Connect the TextEditingController to a text field.

Create a function to print the latest value.