从Flutter中的Text()小部件获取字符串内容

时间:2018-08-21 12:50:52

标签: android text dart flutter

在定义后,是否可以从String小部件中获取Text()值?

示例代码

Text txt = Text("example text");

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

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

2 个答案:

答案 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);