In Flutter, we may wish to use hexadecimal color strings. In this post, we'll look at how to do it.
How to use hexadecimal color strings in Flutter
To use hexadecimal color strings in Flutter we need to:
- convert string to an integer since the
Color class in Flutter accepts only int values,
- we need to set the opacity (255 value is a full opacity represented by the hexadecimal value FF).
The method to convert color in the string to the
Color class in Flutter looks as follows:
FF in line
hexColor = "FF" + hexColor; sets the opacity to
Opacity values in hexadecimal:
The method that takes the opacity also could look like this:
In this article, we learned how to use convert hexadecimal color in strings to the
Color class in Flutter.