相关疑难解决方法(0)

将数据发送到Flutter中的父Widget

我正在尝试将子窗口小部件中的文本设置为父窗口小部件.但是文本没有反映在父窗口小部件中.

试图使用setState()但仍然无法获得预期的结果.

以下是我的代码:

void main() => runApp(new TestApp());

class TestApp extends StatefulWidget {
  @override
  _TestState createState() => new _TestState();
}

class _TestState extends State<TestApp>{

  String abc = "";

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        body: new Column(
          children: <Widget>[
            new Text("This is text $abc"),
            TestApp2(abc)
          ],
        ),
      ),
    );
  }
}


class TestApp2 extends StatefulWidget {

  String abc;

  TestApp2(this.abc);

  @override
  _TestState2 createState() => new _TestState2();
}

class _TestState2 extends State<TestApp2>{
  @override
  Widget build(BuildContext context) { …
Run Code Online (Sandbox Code Playgroud)

dart flutter

16
推荐指数
3
解决办法
1万
查看次数

标签 统计

dart ×1

flutter ×1