When users input a large amount of information, they usually use a list of TextFields to solve the problem. Then, if you need to control or listen to each TextField, you need a large number of TexteditingControllers.

Here is another way to solve the problem of heavy use of TexditingControllers and the difficulty of collating information.

Define a Map:

Map<String, dynamic> _userInfo;

This Map works wherever user information needs to be collected.

To use TextField, do this:

//// TextField(controller: TextEditingController(text: _userInfo['account']),
    onChanged: (value) {
        _userInfo['account'] = value; },), //// nickname TextField(controller: TextEditingController(text: _userInfo['nickname']),
    onChanged: (value) {
        _userInfo['nickname'] = value; },), //// password TextField(controller: TextEditingController(text: _userInfo['password']),
    onChanged: (value) {
        _userInfo['password'] = value; },),Copy the code

The TextEditingController is not defined separately in the whole process. It is only controlled by the default method of TextField, and the following benefits can be obtained:

1. Save a lot of code and simplify business logic.

2. When user input is complete, a Map containing all information is displayed.

3. Input content will not be lost, as long as the Map is not destroyed, the next time you enter (or return) to this page, all the content will be there, do not require the user to enter again, improve the user experience.

This is the first time to post an article. If you have any questions, please correct them.