Reputation: 766
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
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
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