FoxyError
FoxyError

Reputation: 766

Get the String content from a Text() Widget in Flutter

Is it possible to get the String value from a Text() Widget after it is defined?

Example code

Text txt = Text("example text");

getValueFromtxt() {
  var value = txt.text;                  <------
}

@override
Widget build(BuildContext context) {
  return txt;
}

Upvotes: 13

Views: 29706

Answers (2)

Viren V Varasadiya
Viren V Varasadiya

Reputation: 27137

@FoxyError you can do that as above answer but You can Avoid that by just storing value in String variable.

String string = "hello World";

You can use it to print or change the value.

 new Text("Any String" + string);

Upvotes: 0

FoxyError
FoxyError

Reputation: 766

It's not that difficult I had to use Text().data:

Text txt = Text("example text");

getValueFromtxt() {
  var value = txt.data;                  <------
}

@override
Widget build(BuildContext context) {
  return txt;
}

Upvotes: 24

Related Questions