gpt4 book ai didi

dart - Flutter - 使用自定义十六进制颜色

转载 作者:IT王子 更新时间:2023-10-29 07:13:08 25 4
gpt4 key购买 nike

<分区>

如何在 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,但是它们需要一个整数值和样本。是否需要将十六进制值从字符串转换为整数?我想寻找一些代码示例如何实现这一点,如果可能的话:)

提前致谢

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com