toMap method
Output color as Map object
By default, the map will be output with the keys "red", "green" and
"blue". "alpha" will be displayed depending on the format of the object.
You can also specify an arbitrary number of components of said template
.
Default values rgb component output as int. You can change this by
passing a true argument asDouble
. All rgb components of the default set
in the range of 0-255, but you can change this by specifying a range
argument needs range from 0-range (eg from 0 to 1).
Implementation
Map toMap({Map? template, bool asDouble: false, int? range}) {
var defKeys = ["red", "green", "blue", "alpha"],
comps = template == null && alpha == null
? [Component.RED, Component.GREEN, Component.BLUE]
: [Component.RED, Component.GREEN, Component.BLUE, Component.ALPHA],
target = template is Map
? template
: Map.fromIterables(defKeys.sublist(0, comps.length), comps);
return Map.fromIterables(
target.keys,
toList(
template: target.values.toList(),
asDouble: asDouble,
range: range));
}