我正在從 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 種顏色。現在我得到 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(),
],
),
uj5u.com熱心網友回復:
您可以通過以下方式輕松實作:
String color = '#1db8ce';
Color actualColor = Color(int.parse(color.replaceAll('#','0xff')));
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/371748.html
