firstChar method

String firstChar({
  1. bool firstUppercase = true,
  2. int length = 2,
})
'John Doe'.firstChar(length = 2); // JD

Implementation

String firstChar({bool firstUppercase = true, int length = 2}) {
  String result = '';

  try {
    List<String> char = trim().split(' ');
    char
        .take(length)
        .forEach((e) => result += firstUppercase ? e[0].ucwords : e[0]);
    return result;
  } catch (e) {
    return '!';
  }
}