mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 02:57:22 +00:00
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user