change tag color

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2023-08-22 19:07:01 +08:00
parent 115221098a
commit b27c3ff169
40 changed files with 152 additions and 50 deletions

View File

@@ -1077,7 +1077,7 @@ Color str2color(String str, [alpha = 0xFF]) {
return Color((hash & 0xFF7FFF) | (alpha << 24));
}
Color str2color2(String str, [alpha = 0xFF]) {
Color str2color2(String str, {List<int> existing = const []}) {
Map<String, Color> colorMap = {
"red": Colors.red,
"green": Colors.green,
@@ -1094,10 +1094,10 @@ Color str2color2(String str, [alpha = 0xFF]) {
};
final color = colorMap[str.toLowerCase()];
if (color != null) {
return color.withAlpha(alpha);
return color.withAlpha(0xFF);
}
if (str.toLowerCase() == 'yellow') {
return Colors.yellow.withAlpha(alpha);
return Colors.yellow.withAlpha(0xFF);
}
var hash = 0;
for (var i = 0; i < str.length; i++) {
@@ -1105,7 +1105,15 @@ Color str2color2(String str, [alpha = 0xFF]) {
}
List<Color> colorList = colorMap.values.toList();
hash = hash % colorList.length;
return colorList[hash].withAlpha(alpha);
var result = colorList[hash].withAlpha(0xFF);
if (existing.contains(result.value)) {
Color? notUsed =
colorList.firstWhereOrNull((e) => !existing.contains(e.value));
if (notUsed != null) {
result = notUsed;
}
}
return result;
}
const K = 1024;