错误:可选参数的默认值必须是常量



将默认值分配给Color类型的实例变量时出错。只有当我用颜色的阴影值指定颜色时,才会出现这个错误。

错误:可选参数的默认值必须为常量

class CardPanelHeader extends StatelessWidget {
final String leadingPanelText;
final Color leadingPanelTextColor;
final String trailingPanelText;
final Color trailingPanelTextColor;
const CardPanelHeader({
Key key,
this.leadingPanelText,
this.leadingPanelTextColor = Colors.black87,
this.trailingPanelText,
this.trailingPanelTextColor = Colors.grey.shade600,
}) : super(key: key);

我确实检查了这个解决方案,但对我不起作用。

有人能帮我做这个吗。提前感谢!

您可以使用颜色的绝对值作为常数值;将Colors.grey.shade600更改为const Color(0xFF757575)您可以找到颜色的十六进制代码https://material.io/resources/color/

最新更新