parseName static method

String parseName(
  1. String name,
  2. int? letterLimit
)

Implementation

static String parseName(String name, int? letterLimit) {
  // separate each word
  var parts = name.split(' ');
  var initial = '';

  // check length
  if (parts.length > 1) {
    // check max limit
    if (letterLimit != null) {
      for (var i = 0; i < letterLimit; i++) {
        // combine the first letters of each word
        initial += parts[i][0];
      }
    } else {
      // this default, if word > 1
      initial = parts[0][0] + parts[1][0];
    }
  } else {
    // this default, if word <=1
    initial = parts[0][0];
  }
  return initial;
}