【问题标题】:listview does not work in flutter with widget as its child?listview 不能在小部件作为其子项的情况下工作?
【发布时间】:2021-05-15 07:24:00
【问题描述】:

为什么这段代码在 Flutter 中不起作用?它说它不能使用带有

Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: ListView(
          padding: EdgeInsets.symmetric(vertical: 30.0),
          children: <widget>[
              Padding(
                padding: const EdgeInsets.only(left: 20.0, right: 120.0),
                child: Text(
                  'what would you like to find?',
                  style: TextStyle(
                    fontSize: 30.0,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
          ],
        ),
      ),
    ),
  );
  }
}

【问题讨论】:

  • 简单地说,只需删除 。它会正常工作。在 Flutter 中,一切都是小部件

标签: flutter listview widget


【解决方案1】:

我们写Widget,大写W。

Widget 不是widget

【讨论】:

    【解决方案2】:

    首先应该是&lt;Widget&gt;而不是&lt;widget&gt;

    此外,您不必定义 Listview 的子内容。因此,只需将&lt;widget&gt; 全部删除即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-10
      • 2019-07-03
      • 2017-10-03
      • 2021-12-27
      • 2013-11-01
      相关资源
      最近更新 更多