getColorFromString function

Color getColorFromString(
  1. String input
)

Generates a color from a given string

Implementation

Color getColorFromString(String input) {
  // Hash the input string using SHA-256
  var bytes = utf8.encode(input);
  var digest = sha256.convert(bytes);

  // Use the first 3 bytes of the hash to generate RGB values
  int red = (digest.bytes[0] % 128) + 128; // 128-255
  int green = (digest.bytes[1] % 128) + 128; // 128-255
  int blue = (digest.bytes[2] % 128) + 128; // 128-255

  return Color.fromARGB(255, red, green, blue);
}