简体   繁体   English

listview 不能在 flutter 中使用小部件作为其子项?

[英]listview does not work in flutter with widget as its child?

Why does this code not work ins flutter?为什么此代码在 flutter 中不起作用? It says it cannot use the 'Listview' with <widget[] as one of its children?它说它不能使用带有 <widget[] 的“Listview”作为其子项之一?

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,
                  ),
                ),
              ),
          ],
        ),
      ),
    ),
  );
  }
}

We write Widget with a capital W.我们用大写的 W 编写Widget

Widget not widget Widget不是widget

First of all, it should be <Widget> and not <widget>首先,它应该是<Widget>而不是<widget>

Also, you don't have to define the children content of a Listview.此外,您不必定义 Listview 的子内容。 So just remove <widget> alltogether.因此,只需将<widget>全部删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM