I have a TextEditingController
where if a user clicks a button it fills in with information. I can\'t seem to figure out how to change the text inside of a
TextEditingController()..text = "new text"
First Thing
TextEditingController MyController= new TextEditingController();
Then add it to init State or in any SetState
MyController.value = TextEditingValue(text: "ANY TEXT");
Simply change the text
property
TextField(
controller: txt,
),
RaisedButton(onPressed: () {
txt.text = "My Stringt";
}),
while txt
is just a TextEditingController
var txt = TextEditingController();
You can use the text editing controller to manipulate the value inside a textfield.
var textController = new TextEditingController();
Now, create a new textfield and set textController
as the controller for the textfield as shown below.
new TextField(controller: textController)
Now, create a RaisedButton
anywhere in your code and set the desired text in the onPressed
method of the RaisedButton
.
new RaisedButton(
onPressed: () {
textController.text = "New text";
}
),