【发布时间】:2022-01-05 04:53:24
【问题描述】:
我的模型颤振项目有问题.. 我收到一个错误:
参数类型“对象?”不能分配给参数类型 '字符串'。
参数类型“对象?”不能分配给参数类型 '诠释'。
参数类型“对象?”不能分配给参数类型 '字符串'。
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'])
感谢您的回答..
【问题讨论】:
-
不完全确定,但有两件事从我的脑海中浮现出来 - 1. 'courses':应该是“courses”:在你的 Json 中?另外,2. 也许 item[] 变量需要作为 item['name'] 传递! (末尾有感叹号)为空安全? (第2点可能不对....)