英文:
element type 'List<widget>' can't be assigned to the list type 'Widget'
问题
element type 'List<Widget>' can't be assigned to the list type 'Widget'** and second **the argument type "gridview" can't be assigned to the parameter type "iterable<Widget>".
        List<Widget> categoriesWidgets;
        String categoryCaption;
        final List<Widget> result = <Widget>[];
英文:
I am trying to output title (string) and list of items (widgets), but it is showing two errors.
one is
>element type 'List<widget>' can't be assigned to the list type 'Widget'** and second **the argument type "gridview" can't be assigned to the parameter type "iterable<widget>".
    List<Widget> categoriesWidgets;
    String categoryCaption,
    final List<Widget> result = <Widget>[];
    final Padding categoryTitleWidget = Padding(
    padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
    child: Text(categoryCaption));
    final GridView results = GridView.count(crossAxisCount: 2,
        children: <Widget>[result]
    );
    categoriesWidgets.add(categoryTitleWidget);
    categoriesWidgets.addAll(results);
    }
答案1
得分: 3
你正试图创建 array of list of Widget,但期望的是 list of widget。
将
 children: <Widget>[result]
修改为
 children: result
编辑: "grid view 无法分配给可迭代类型的参数"
将以下代码更改为:
categoriesWidgets.addAll([results]); // 将 results 添加到 []
英文:
You are trying to create array of list of Widget. But the expected is list of widget.
Change
 children: <Widget>[result]
to
 children: result
Edit: "grid view can't be assigned to parameter type iterable"
Change the following code to:
categoriesWidgets.addAll([results]); // add results within []
答案2
得分: 1
results 是一个单个小部件 GridView,它应该使用 add 而不是 addAll。
  final GridView results = GridView.count(crossAxisCount: 2, children: result);
  categoriesWidgets.add(categoryTitleWidget);
  categoriesWidgets.add(results);
英文:
The results is a single widget GridView, it should use add instead of addAll.
  final GridView results = GridView.count(crossAxisCount: 2,children: result);
  categoriesWidgets.add(categoryTitleWidget);
  categoriesWidgets.add(results);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。



评论