I'm Getting all my data from Api. I want to convert the Color string value to Actual color. How can I achieve that?
My API response:
{
"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"
}
]
},
...................................................
I'm trying to display those 2 color, which is coming from my API in a Row(). For now I'm getting 2 Red color box (as I set the Color Red manually).
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(),
],
),
CodePudding user response:
You can easily achieve it this way:
String color = '#1db8ce';
Color actualColor = Color(int.parse(color.replaceAll('#','0xff')));