In flutter you can use a variable as a property of a Text. For example if you declare:

String myVar= "Hello world";

When you use it:

Text(myVar)

and then you change the value of the variable myVar, also the text of the Text object will change.

So, is it possibile to do something like that with the text of a textfield? Or the only way is to use a TextEditingController and then change every time the text property of this object.


Solution 1: diegoveloper

You can find more information here: https://flutter.io/tutorials/interactive/

This is what @Gunter is talk about:

    class SampleWidgetState extends State<SampleWidget> {
      String myVar = "Hello world";

      @override
      Widget build(BuildContext context) {
        return Center(
          child: Column(
            children: <Widget>[
              Text(myVar),
              RawMaterialButton(
                child: Text("press me"),
                onPressed: () {
                  setState(() {
                    myVar = "By World";
                  });
                },
              )
            ],
          ),
        );
      }
    }