<分区>
如何在 Flutter 中添加十六进制值的颜色?例如,我正在尝试以下操作:
Widget build(BuildContext context) {
return Row(
children: <Widget>[
Expanded(
child: Container(
padding: EdgeInsets.only(left: 20.0),
height: 100.0,
decoration: BoxDecoration(
color: Color.hex("#183451"),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Image.asset('assets/main_image.png'),
// More widgets here
],
),
),
),
],
);
}
但是得到如下错误:
Error: The argument type 'color::Color' can't be assigned to the parameter type 'dart.ui::Color
这是使用“颜色”包: https://pub.dartlang.org/packages/color
如果我使用 MaterialColor
,它将按预期工作:
color: Colors.blue
我想我需要创建一个 MaterialColor
,但是它们需要一个整数值和样本。是否需要将十六进制值从字符串转换为整数?我想寻找一些代码示例如何实现这一点,如果可能的话:)
提前致谢