Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

Flutter cant show string color code in color

I need to show the color from in my container. Mean i have color codes in string format and i need to use as the Container Color.

                  decoration: BoxDecoration(
                  color: widget.product.colors[i].toColor(),
                  borderRadius: BorderRadius.all(Radius.circular(40)),

This is the simple code i am doing like this but its showing error

Invalid argument(s): Can not interpret string 0xFFF6625E

If i remove the .toColor() then its showing

Error: The argument type 'String' can't be assigned to the parameter type 'Color'.

Can any one please tell how can i show this ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use below code:

  decoration: BoxDecoration(
    //make sure that the widget.product.colors[i] is a hex code (i.e: "0xff0000")
     color : Color(int.parse(widget.product.colors[i])),
     borderRadius: BorderRadius.all(Radius.circular(40)),
     border: Border.all(color: Color(int.parse(kPrimaryColor)))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...