我想将 Colors.red.shade900 的默认颜色设置为我的自定义小部件,但它显示错误
这是我的自定义课程:
class ChartHeader extends StatelessWidget {
final String title;
final Color backgroundColor;
const ChartHeader({
Key? key,
required this.title,
this.backgroundColor = Colors.red.shade900,
}) : super(key: key);
我应该为 Colors.red.shade900 使用什么数据类型?
这不是错误的数据类型,但
Colors.red.shade900
的值不是恒定的。
您可以使用等效的常量值:
Color(0xFFB71C1C)
,如下所示:
class ChartHeader extends StatelessWidget {
final String title;
final Color backgroundColor;
const ChartHeader({
Key? key,
required this.title,
this.backgroundColor = Color(0xFFB71C1C),
}) : super(key: key);
您可以通过按
ctrl + click-on-theClass
检查 Dart 中任何颜色的值