简体   繁体   中英

The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<Widget>'

I am getting the above error (question) with the following code:

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(),

dummy_data

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

I am just following a tutorial. The instructor did not get the error. :(

specify the type of the map map<Widget>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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