无法将参数类型 'Object?' 分配给参数类型 'String'。?

The argument type 'Object?' can't be assigned to the parameter type 'String'.?

我的模型 flutter 项目有问题.. 我得到一个错误:

The argument type 'Object?' can't be assigned to the parameter type 'String'.

The argument type 'Object?' can't be assigned to the parameter type 'Int'.

The argument type 'Object?' can't be assigned to the parameter type 'String'.

class Category {
  final String name;
  final int numOfCourses;
  final String image;

  Category(this.name, this.numOfCourses, this.image);
}

List<Category> categories = categoriesData
    .map((item) => Category(item['name'], item['courses'], item['image']))
    .toList();

var categoriesData = [
  {"name": "Marketing", 'courses': 17, 'image': "assets/images/marketing.png"},
  {"name": "UX Design", 'courses': 25, 'image': "assets/images/ux_design.png"},
  {
    "name": "Photography",
    'courses': 13,
    'image': "assets/images/photography.png"
  },
  {"name": "Business", 'courses': 17, 'image': "assets/images/business.png"},
];

这部分有错误

(item['name'], item['courses'], item['image'])

感谢您的回答..

Dart 不知道 categoriesData['name']categoriesData['courses']categoriesData['image'] 应该是什么,要告诉它,您可以使用 as 关键字:

categories = categoriesData
    .map((item) => Category(item['name'] as String, item['courses'] as int, item['image'] as String))
    .toList();