Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 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(),
                                            ],
                                          ),

>Solution :

You can easily achieve it this way:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading