add tag color

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages committed 2023-08-14 11:58:18 +08:00
1 parent ae640dda56
commit a5bba37cae
3 files changed
+139 -18

No files matched your search

+24
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;