getColorFromPubkey static method
Implementation
static Color getColorFromPubkey(String pubkey) {
// Hash the pubkey using SHA-256 for better distribution
final bytes = utf8.encode(pubkey);
final digest = sha256.convert(bytes);
// Use first 3 bytes of hash for RGB values
final hashBytes = digest.bytes;
final r = hashBytes[0];
final g = hashBytes[1];
final b = hashBytes[2];
// Create color from RGB values
final color = Color.fromARGB(255, r, g, b);
// Convert to HSL to ensure good visibility
final hslColor = HSLColor.fromColor(color);
// Adjust saturation and lightness for better visibility
// Keep hue from hash but ensure readable colors
final adjustedHslColor = hslColor.withSaturation(0.6).withLightness(0.45);
return adjustedHslColor.toColor();
}