flutter - 错误:可选参数的默认值必须是常量
问题描述
将默认值分配给 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/