add tag color

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-08-13 18:13:06 +08:00
parent ae640dda56
commit a5bba37cae
3 changed files with 139 additions and 18 deletions

View File

@@ -1074,6 +1074,30 @@ Color str2color(String str, [alpha = 0xFF]) {
return Color((hash & 0xFF7FFF) | (alpha << 24));
}
Color str2color2(String str, [alpha = 0xFF]) {
List<Color> colorList = [
Colors.red,
Colors.green,
Colors.blue,
Colors.orange,
Colors.yellow,
Colors.purple,
Colors.grey,
Colors.cyan,
Colors.lime,
Colors.teal,
Colors.pink,
Colors.indigo,
Colors.brown,
];
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash += str.codeUnitAt(i);
}
hash = hash % colorList.length;
return colorList[hash].withAlpha(alpha);
}
const K = 1024;
const M = K * K;
const G = M * K;