在定义后,是否可以从String
小部件中获取Text()
值?
示例代码
Text txt = Text("example text");
getValueFromtxt() {
var value = txt.text; <------
}
@override
Widget build(BuildContext context) {
return txt;
}
答案 0 :(得分:4)
使用Text().data
并不难:
Text txt = Text("example text");
getValueFromtxt() {
var value = txt.data; <------
}
@override
Widget build(BuildContext context) {
return txt;
}
答案 1 :(得分:1)
@FoxyError您可以按照上述答案进行操作,但是您可以通过将值存储在String变量中来避免这种情况。
String string = "hello World";
您可以使用它来打印或更改值。
new Text("Any String" + string);