toColor static method
Return a int of 'bit hex':
Its return is proper to use as hex color int
in a Color()
For example: ... color: Color(StringToHex().toColor('a nice String')) ...
then it'll generate and fill a hex-color int in it.
return a hex-color.
i.e: 0xFF353535
or: 8787451701
Implementation
/// return a hex-color.
/// i.e: 0xFF353535
/// or: 8787451701
static int toColor(str) {
try {
var hash = _getInt(str);
var r = (hash & 0xFF0000) >> 16;
var g = (hash & 0x00FF00) >> 8;
var b = hash & 0x0000FF;
var rr = r.toString();
var gg = g.toString();
var bb = b.toString();
return int.parse('0xFF' +
rr.substring(rr.length - 2) +
gg.substring(gg.length - 2) +
bb.substring(bb.length - 2));
} catch (err) {
print('Error: String Must be greater than range 2\n'
'=========== hash string to hex ===========\n'
' string length = ${str.length}');
rethrow;
}
}