【发布时间】:2026-01-14 12:20:04
【问题描述】:
我的班级中有这个构造函数。现在当它是这样的时候,我得到了
The type parameter icon is annotated with @required
but only named parameters without default value can be annotated with it.
-
const Category(
@required this.name,
@required this.icon,
@required this.color
) : assert(name != null),
assert(icon != null),
assert(color != null);
当这样调用构造函数时:
Category(name: _categoryName, icon: _categoryIcon, color: _categoryColor),
这是一个错误。
当我用 {} 包围我的构造函数参数时,所有这些都消失了。
这是什么意思?
【问题讨论】:
-
这不仅适用于构造函数,也适用于函数