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

 child: Row(
                                            children: [
                                              for (var colorListListVar in[index].colorList)
                                                  margin: EdgeInsets.only(right: 2),
                                                  padding: EdgeInsets.all(getProportionateScreenWidth(8)),
                                                  decoration: BoxDecoration(
                                                    color: Colors.transparent,
                                                    //border: Border.all(color: kPrimaryColor),
                                                  child: DecoratedBox(
                                                    decoration: BoxDecoration(
                                                      color:, //I want to use like this ==> colorListListVar.ProductColor


You can easily achieve it this way:

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

Answered By – esentis

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More