getAvatarTitle static method

String getAvatarTitle(
  1. String name
)

This function is used to get the avatar title

Implementation

static String getAvatarTitle(String name) {
  if (name.isEmpty) {
    return "👤";
  }
  if (name.contains(regexEmoji)) {
    name = name.replaceAll(regexEmoji, '');
    if (name.trim().isEmpty) {
      return '😄';
    }
  }
  List<String>? parts = name.trim().split(" ");
  if (parts.length == 1) {
    name = parts[0].substring(0, math.min(2, parts[0].length));
  } else if (parts.length >= 2) {
    name = parts[0][0];
    if (parts[1] == "" || parts[1] == " ") {
      name += parts[0][1];
    } else {
      name += parts[1][0];
    }
  }
  return name.toUpperCase();
}