September 2019
Beginner
512 pages
12h 52m
English
When used isolated from a Form, that is, by using the TextField widget, we need to use its controller property to access its value. This is done with the TextEditingController class:
final _controller = TextEditingController.fromValue( TextEditingValue(text: "Initial value"), );
After instantiating the TextEditingController, we set it into the controller property of the TextField widget so that it "controls" the text widget:
TextField( controller: _controller,);
As you can see, we can set an initial value for the TextField as well.
TextEditingController is notified whenever the TextField widget has a new value. To listen to changes, we need to add a listener to our _controller:
_controller.addListener(_textFieldEvent); ...
Read now
Unlock full access