如何将 API 颜色代码 ("#1db8ce") 值转换为实际 RGB 颜色?

How to convert API color code ("#1db8ce") value to Actual RGB color?

我正在从 Api 获取所有数据。我想将颜色字符串值转换为实际颜色。我怎样才能做到这一点?

我的 API 回复:

{
"Status": 1,
"Message": "",
"ProductList": [
    {
        "CategoryId": "2",
        "CategoryName": "Women",
        "SubCategoryId": "14",
        "SubCategoryName": "Nighty",
        "DiscountStartDate": "",
        "DiscountEndDate": "",
        "Tag": "Nighty",
       
     
        "ColorList": [
            {
                "ProductId": "52",
                "ProductColor": "#1db8ce"
            },
            {
                "ProductId": "52",
                "ProductColor": "#8ab234"
            }
        ]
    },
   ...................................................

我正在尝试显示这两种颜色,它们来自我在 Row() 中的 API。现在我得到 2 个红色框(因为我手动设置了红色)。

 child: Row(
                                            children: [
                                              for (var colorListListVar in snapshot.data.productList[index].colorList)
                                                Container(
                                                  margin: EdgeInsets.only(right: 2),
                                                  padding: EdgeInsets.all(getProportionateScreenWidth(8)),
                                                  height:getProportionateScreenWidth(40),
                                                  width:getProportionateScreenWidth(40),
                                                  decoration: BoxDecoration(
                                                    color: Colors.transparent,
                                                    //border: Border.all(color: kPrimaryColor),
                                                    shape: BoxShape.circle,
                                                  ),
                                                  child: DecoratedBox(
                                                    decoration: BoxDecoration(
                                                      color: Colors.red, //I want to use like this ==> colorListListVar.ProductColor
                                                      shape:BoxShape.circle,
                                                    ),
                                                  ),
                                                ),
                                              Spacer(),
                                            ],
                                          ),

您可以通过这种方式轻松实现:

String color = '#1db8ce';
Color actualColor = Color(int.parse(color.replaceAll('#','0xff')));