【问题标题】:The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<Widget>'参数类型“List<dynamic>”不能分配给参数类型“List<Widget>”
【发布时间】:2021-10-24 13:40:15
【问题描述】:

我收到上述错误(问题),代码如下:

Widget build(BuildContext context) {
return Scaffold(
  appBar: AppBar(title: const Text('DeliMeals')),
  body: GridView(
    children: DUMMY_CATEGORIES
        .map((categoryData) => CategoryItem(   //getting
              categoryData.title,             //the error
              categoryData.color,            //here
            ))
        .toList(),

虚拟数据

const DUMMY_CATEGORIES = const [
Category(
id: 'c1',
title: 'Italian',
color: Colors.purple,
),
Category(
id: 'c2',
title: 'Quick & Easy',
color: Colors.red,
),
];

我只是在学习一个教程。导师没有得到错误。 :(

【问题讨论】:

  • 也请分享 CategoryItem 代码
  • .map 更改为 .map&lt;Widget&gt;。下次请用搜索,这个已经问了很多次了

标签: android flutter widget


【解决方案1】:

指定地图类型map&lt;Widget&gt;

DUMMY_CATEGORIES
        .map<Widget>((categoryData) => CategoryItem(   
              categoryData.title,             
              categoryData.color,            
            ))
        .toList(),

【讨论】:

    猜你喜欢
    • 2021-07-04
    • 2021-09-15
    • 2021-10-18
    • 2021-09-13
    • 2019-10-05
    • 2021-11-13
    • 2021-12-24
    • 2020-10-11
    • 1970-01-01
    相关资源
    最近更新 更多