0

I need to bind the color code in a flutter. I have code like this.

 color: Color(int.parse(widget.product.colors[i]))

Issue is previously i have full hex code in widget.product.colors[i] like 0xFF223263 but now i have just #223263. How can I bind this mean add before this

Mean something like

 color: Color(int.parse(0xff$widget.product.colors[i]))

Mean if I need to add 0xff before the colors so it can show in-app

rameez khan
  • 73
  • 1
  • 23
  • 68

2 Answers2

1
var col = widget.product.colors[i];
var stringCol = "ff" + col.substring(1, 7);
var intCol = int.parse(finalCol, radix : 16);
Color finalCol = new Color(intCol);

Use this finalCol wherever you want

if it's a text, then

Text('Hello World', style = TextStyle(color: finalCol));

Voila...

Sravan Kumar
  • 602
  • 8
  • 22
0

Remove the # then concatenate 0xff with the rest of the hex numbers

Like so

Color(int.parse("0xff${widget.product.colors[i].replaceAll("#", "")}"))
Josteve
  • 11,459
  • 1
  • 23
  • 35