Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
}
like image 778
FoxyError Avatar asked Aug 21 '18 12:08

FoxyError


People also ask

How do I get text data in Flutter?

To retrieve data fom a Text widget, var data=Text("18:00"); print(data. data); This will give you the output "18:00" as per your requirement.

What is of () in Flutter?

In the Flutter SDK the . of methods are a kind of service locator function that take the framework BuildContext as an argument and return an internal API related to the named class but created by widgets higher up the widget tree.


1 Answers

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;
}
like image 90
FoxyError Avatar answered Oct 05 '22 13:10

FoxyError