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;
}
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.
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.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With