0

Cannot find a clue why i can't set an initial text at TextEditingController as the parameter: following code works well:

TextEditingController _usernameController =
  TextEditingController(text: 'test');

But if i change hardcoded value to a parameter it brokes:

String _test = 'test';

TextEditingController _usernameController =
    TextEditingController(text: _test);

How to solve this problem? Thanks a lot

1 Answers1

0

You can try something like this

String _test = 'test';
TextEditingController _usernameController = TextEditingController();

...
TextFormField(
         controller: _usernameController..text = this._test,
Ibrahim Ali
  • 2,083
  • 2
  • 15
  • 36