initials method

String initials()

Returns initials (two letters which begin each word) of this string.

Implementation

String initials() {
  List<String> words = split(' ').where((e) => e.isNotEmpty).toList();

  if (words.length >= 2) {
    return '${words[0][0]}${words[1][0]}'.toUpperCase();
  } else if (words.isNotEmpty) {
    if (words[0].length >= 2) {
      return '${words[0][0].toUpperCase()}${words[0][1].toLowerCase()}';
    } else {
      return words[0].toUpperCase();
    }
  }

  return '';
}