1+ import 'internal/raw_css_colors.dart' ;
2+
13/// Validates and retrieves the color string in hexadecimal format.
24///
35/// If [colorString] starts with '#', it's assumed to be already in hexadecimal format.
@@ -35,7 +37,7 @@ String? validateAndGetColor(String colorString) {
3537/// - If [color] starts with 'hsl(', converts it using [hslToHex] .
3638/// - If [color] starts with 'hsla(', converts it using [hslaToHex] .
3739/// - Otherwise, treats it as a color name and converts it using [colorNameToHex] .
38- ///
40+ ///
3941/// Throws [ArgumentError] if the color format is not supported.
4042///
4143/// Parameters:
@@ -238,15 +240,15 @@ String _toHex(int r, int g, int b, int a) {
238240}
239241
240242/// Converts a color name to its hexadecimal representation.
241- ///
243+ ///
242244/// If the color name is not found in the predefined map, it throws an [ArgumentError] .
243- ///
245+ ///
244246/// Parameters:
245247/// - [colorName] : The name of the color to convert to hexadecimal format.
246- ///
248+ ///
247249/// Returns:
248250/// The hexadecimal representation of the color name.
249- ///
251+ ///
250252/// Example:
251253/// ```dart
252254/// print(colorNameToHex('red')); // Output: #FF0000
@@ -257,163 +259,9 @@ String colorNameToHex(String colorName) {
257259 String normalizedColorName = colorName.toLowerCase ();
258260
259261 // Check if the color name exists in the map
260- if (_colorNameToHexMap .containsKey (normalizedColorName)) {
261- return _colorNameToHexMap [normalizedColorName]! ;
262+ if (colorNameToHexMap .containsKey (normalizedColorName)) {
263+ return colorNameToHexMap [normalizedColorName]! ;
262264 } else {
263265 throw ArgumentError ('Color name "$colorName " is not supported.' );
264266 }
265267}
266-
267- /// A map of color names to their hexadecimal representations.
268- ///
269- /// Source: https://www.w3.org/TR/css-color-4/#named-colors
270- Map <String , String > _colorNameToHexMap = {
271- "aliceblue" : "#f0f8ff" ,
272- "antiquewhite" : "#faebd7" ,
273- "aqua" : "#00ffff" ,
274- "aquamarine" : "#7fffd4" ,
275- "azure" : "#f0ffff" ,
276- "beige" : "#f5f5dc" ,
277- "bisque" : "#ffe4c4" ,
278- "black" : "#000000" ,
279- "blanchedalmond" : "#ffebcd" ,
280- "blue" : "#0000ff" ,
281- "blueviolet" : "#8a2be2" ,
282- "brown" : "#a52a2a" ,
283- "burlywood" : "#deb887" ,
284- "cadetblue" : "#5f9ea0" ,
285- "chartreuse" : "#7fff00" ,
286- "chocolate" : "#d2691e" ,
287- "coral" : "#ff7f50" ,
288- "cornflowerblue" : "#6495ed" ,
289- "cornsilk" : "#fff8dc" ,
290- "crimson" : "#dc143c" ,
291- "cyan" : "#00ffff" ,
292- "darkblue" : "#00008b" ,
293- "darkcyan" : "#008b8b" ,
294- "darkgoldenrod" : "#b8860b" ,
295- "darkgray" : "#a9a9a9" ,
296- "darkgreen" : "#006400" ,
297- "darkgrey" : "#a9a9a9" ,
298- "darkkhaki" : "#bdb76b" ,
299- "darkmagenta" : "#8b008b" ,
300- "darkolivegreen" : "#556b2f" ,
301- "darkorange" : "#ff8c00" ,
302- "darkorchid" : "#9932cc" ,
303- "darkred" : "#8b0000" ,
304- "darksalmon" : "#e9967a" ,
305- "darkseagreen" : "#8fbc8f" ,
306- "darkslateblue" : "#483d8b" ,
307- "darkslategray" : "#2f4f4f" ,
308- "darkslategrey" : "#2f4f4f" ,
309- "darkturquoise" : "#00ced1" ,
310- "darkviolet" : "#9400d3" ,
311- "deeppink" : "#ff1493" ,
312- "deepskyblue" : "#00bfff" ,
313- "dimgray" : "#696969" ,
314- "dimgrey" : "#696969" ,
315- "dodgerblue" : "#1e90ff" ,
316- "firebrick" : "#b22222" ,
317- "floralwhite" : "#fffaf0" ,
318- "forestgreen" : "#228b22" ,
319- "fuchsia" : "#ff00ff" ,
320- "gainsboro" : "#dcdcdc" ,
321- "ghostwhite" : "#f8f8ff" ,
322- "gold" : "#ffd700" ,
323- "goldenrod" : "#daa520" ,
324- "gray" : "#808080" ,
325- "green" : "#008000" ,
326- "greenyellow" : "#adff2f" ,
327- "grey" : "#808080" ,
328- "honeydew" : "#f0fff0" ,
329- "hotpink" : "#ff69b4" ,
330- "indianred" : "#cd5c5c" ,
331- "indigo" : "#4b0082" ,
332- "ivory" : "#fffff0" ,
333- "khaki" : "#f0e68c" ,
334- "lavender" : "#e6e6fa" ,
335- "lavenderblush" : "#fff0f5" ,
336- "lawngreen" : "#7cfc00" ,
337- "lemonchiffon" : "#fffacd" ,
338- "lightblue" : "#add8e6" ,
339- "lightcoral" : "#f08080" ,
340- "lightcyan" : "#e0ffff" ,
341- "lightgoldenrodyellow" : "#fafad2" ,
342- "lightgray" : "#d3d3d3" ,
343- "lightgreen" : "#90ee90" ,
344- "lightgrey" : "#d3d3d3" ,
345- "lightpink" : "#ffb6c1" ,
346- "lightsalmon" : "#ffa07a" ,
347- "lightseagreen" : "#20b2aa" ,
348- "lightskyblue" : "#87cefa" ,
349- "lightslategray" : "#778899" ,
350- "lightslategrey" : "#778899" ,
351- "lightsteelblue" : "#b0c4de" ,
352- "lightyellow" : "#ffffe0" ,
353- "lime" : "#00ff00" ,
354- "limegreen" : "#32cd32" ,
355- "linen" : "#faf0e6" ,
356- "magenta" : "#ff00ff" ,
357- "maroon" : "#800000" ,
358- "mediumaquamarine" : "#66cdaa" ,
359- "mediumblue" : "#0000cd" ,
360- "mediumorchid" : "#ba55d3" ,
361- "mediumpurple" : "#9370db" ,
362- "mediumseagreen" : "#3cb371" ,
363- "mediumslateblue" : "#7b68ee" ,
364- "mediumspringgreen" : "#00fa9a" ,
365- "mediumturquoise" : "#48d1cc" ,
366- "mediumvioletred" : "#c71585" ,
367- "midnightblue" : "#191970" ,
368- "mintcream" : "#f5fffa" ,
369- "mistyrose" : "#ffe4e1" ,
370- "moccasin" : "#ffe4b5" ,
371- "navajowhite" : "#ffdead" ,
372- "navy" : "#000080" ,
373- "oldlace" : "#fdf5e6" ,
374- "olive" : "#808000" ,
375- "olivedrab" : "#6b8e23" ,
376- "orange" : "#ffa500" ,
377- "orangered" : "#ff4500" ,
378- "orchid" : "#da70d6" ,
379- "palegoldenrod" : "#eee8aa" ,
380- "palegreen" : "#98fb98" ,
381- "paleturquoise" : "#afeeee" ,
382- "palevioletred" : "#db7093" ,
383- "papayawhip" : "#ffefd5" ,
384- "peachpuff" : "#ffdab9" ,
385- "peru" : "#cd853f" ,
386- "pink" : "#ffc0cb" ,
387- "plum" : "#dda0dd" ,
388- "powderblue" : "#b0e0e6" ,
389- "purple" : "#800080" ,
390- "rebeccapurple" : "#663399" ,
391- "red" : "#ff0000" ,
392- "rosybrown" : "#bc8f8f" ,
393- "royalblue" : "#4169e1" ,
394- "saddlebrown" : "#8b4513" ,
395- "salmon" : "#fa8072" ,
396- "sandybrown" : "#f4a460" ,
397- "seagreen" : "#2e8b57" ,
398- "seashell" : "#fff5ee" ,
399- "sienna" : "#a0522d" ,
400- "silver" : "#c0c0c0" ,
401- "skyblue" : "#87ceeb" ,
402- "slateblue" : "#6a5acd" ,
403- "slategray" : "#708090" ,
404- "slategrey" : "#708090" ,
405- "snow" : "#fffafa" ,
406- "springgreen" : "#00ff7f" ,
407- "steelblue" : "#4682b4" ,
408- "tan" : "#d2b48c" ,
409- "teal" : "#008080" ,
410- "thistle" : "#d8bfd8" ,
411- "tomato" : "#ff6347" ,
412- "turquoise" : "#40e0d0" ,
413- "violet" : "#ee82ee" ,
414- "wheat" : "#f5deb3" ,
415- "white" : "#ffffff" ,
416- "whitesmoke" : "#f5f5f5" ,
417- "yellow" : "#ffff00" ,
418- "yellowgreen" : "#9acd32"
419- };
0 commit comments