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
  • 257
  • 9
  • 29

2 Answers2

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
  • 8,244
  • 1
  • 13
  • 27
0
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
  • 522
  • 7
  • 20