tag color same as tag name if name is color, remove yellow random tag color

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2023-08-15 09:52:02 +08:00
parent 57b8ec178c
commit e01377e100

View File

@ -1078,25 +1078,32 @@ Color str2color(String str, [alpha = 0xFF]) {
} }
Color str2color2(String str, [alpha = 0xFF]) { Color str2color2(String str, [alpha = 0xFF]) {
List<Color> colorList = [ Map<String, Color> colorMap = {
Colors.red, "red": Colors.red,
Colors.green, "green": Colors.green,
Colors.blue, "blue": Colors.blue,
Colors.orange, "orange": Colors.orange,
Colors.yellow, "purple": Colors.purple,
Colors.purple, "grey": Colors.grey,
Colors.grey, "cyan": Colors.cyan,
Colors.cyan, "lime": Colors.lime,
Colors.lime, "teal": Colors.teal,
Colors.teal, "pink": Colors.pink[200]!,
Colors.pink, "indigo": Colors.indigo,
Colors.indigo, "brown": Colors.brown,
Colors.brown, };
]; final color = colorMap[str.toLowerCase()];
if (color != null) {
return color.withAlpha(alpha);
}
if (str.toLowerCase() == 'yellow') {
return Colors.yellow.withAlpha(alpha);
}
var hash = 0; var hash = 0;
for (var i = 0; i < str.length; i++) { for (var i = 0; i < str.length; i++) {
hash += str.codeUnitAt(i); hash += str.codeUnitAt(i);
} }
List<Color> colorList = colorMap.values.toList();
hash = hash % colorList.length; hash = hash % colorList.length;
return colorList[hash].withAlpha(alpha); return colorList[hash].withAlpha(alpha);
} }