How do you change the value inside of a textfield flutter?

后端 未结 10 1666
忘掉有多难
忘掉有多难 2020-12-06 08:49

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

相关标签:
10条回答
  • 2020-12-06 09:30
    TextEditingController()..text = "new text"
    
    0 讨论(0)
  • 2020-12-06 09:34

    First Thing

      TextEditingController MyController= new TextEditingController();
    

    Then add it to init State or in any SetState

        MyController.value = TextEditingValue(text: "ANY TEXT");
    
    0 讨论(0)
  • 2020-12-06 09:35

    Simply change the text property

        TextField(
          controller: txt,
        ),
        RaisedButton(onPressed: () {
            txt.text = "My Stringt";
        }),
    

    while txt is just a TextEditingController

      var txt = TextEditingController();
    
    0 讨论(0)
  • 2020-12-06 09:37

    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";
           }
        ),
    
    0 讨论(0)
提交回复
热议问题