How do I convert three digit hexadecimal String to Color in flutter
Web defines colours in three ways: explicit colour name, 3 hex digits, or 6 hex digits.
If you have 3 digits, you should "double" every digit (as character, not as value), so #abc is to be read as #aabbcc. Why? It is short, and it helped to select fewer colours (in the olden time we have 8 or 16bit colours), and screens may not be so accurate.
Do your #0ff
should be read as #00ffff
.
Note: These 3 digit colours are now considered obsolote, see https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#simple-colour, but still used on many places (e.g. #fff for white).
Balaji
Updated on January 01, 2023Comments
-
Balaji over 1 year
I want to convert "#0ff" this hexadecimal string into Color
I have searched it But I only found answers with the hexadecimal string with length 6 digits
If I do like this
Color(0xFF0ff)
It displays nothingThanks in advance!
-
Giacomo Catenazzi over 2 yearsWeb defines colours in three ways: explicit colour name, 3 hex digits, or 6 hex digits. So
#0ff
is a colour, and most programs (and for sure web) understand it. But a #abc is equivalent to #aabbcc. Just write twice every digit (as character)
-
-
Randal Schwartz over 2 yearsWouldn't #fff be white, not black?
-
Giacomo Catenazzi over 2 years@RandalSchwartz: right, corrected. Thanks
-
Myndex over 2 yearswhatwg.org is NOT the standard for colors on the web, and your claim that 3 digit hex is obsolete is false. Here is the actual standard: w3.org/TR/css-color-3/#numerical ... whatwg.org you linked is the standard for basic HTML, and "simple" colors, but that is not the standard for color on the web. A different WHATWG document points there: html.spec.whatwg.org/multipage/…
-
Giacomo Catenazzi over 2 years@Myndex: "considered obsolete". For sure it will not disappear in next 10 years, and obviously standard needs to explain also the 3 digits. It is not recommended to use, "obsolete" doesn't mean not to be used. If Whatwg is not the reference for web, what do you consider reference? w3c? but usually they are aligned (maybe with some delay)
-
Myndex over 2 yearsYou are not looking at the correct standard for color. I responded in depth in my answer to the OP. You are referencing the HTML, and HTML is not where colors belong in the first place, they belong in CSS, and I assure you that #rgb is not obsolete nor depreciated, and is in the standard released just last month. W3 is part of WHATWG, but HTML is the wrong standard to reference for this context. CSS 3 is the current canonical standard, and yes it is at the W3 as I linked in my answer.