I have color value Color(0XFFDDDDDD) stored as a string in my database. I want it to convert to Color widget in flutter. How can I do it?
Here is image of flutter color value picked from color picker.
I tried spliting the string to remove Color() and to take 0XFFDDDDDD value but it didnt’t worked. I want to be able to use this string value to color value like: Container(color: Color(0XFFDDDDDD))
2
Answers
This should work:
This will give you the Hex colour string
Parse it to a color:
Color(int.parse(hex));
Ideally, your hex colour should also be saved as a pure hex colour in the DB so that you do not have to format the string unnecessarily.
Btw if the parsing doesn’t work try this extension: