getInitials method

String getInitials({
  1. required String string,
  2. required int limitTo,
})

Implementation

String getInitials({required String string, required int limitTo}) {
  var buffer = StringBuffer();
  var split = string.split(' ');
  if (limitTo > split.length) {
    limitTo = split.length;
  }
  for (var i = 0; i < limitTo; i++) {
    if (split[i].isNotEmpty) {
      buffer.write(split[i][0]);
    }
  }

  return buffer.toString();
}