getInitials method

String getInitials({
  1. int limit = 2,
})

Implementation

String getInitials({int limit = 2}) {
  List<String> words = split(" ");
  String initials = "";
  int numWords = 1;

  words.remove('');

  if (numWords < words.length) {
    numWords = words.length;
  }
  for (var i = 0; i < numWords; i++) {
    if (initials.length <= 1) {
      initials += words[i][0];
    }
  }
  return initials.toUpperCase();
}