toTitleCase method

String toTitleCase(
  1. String s
)

Returns a string with the first letter of each word capitalised.

Implementation

String toTitleCase(String s) {
  final words = [
    for (final word in s.split(' '))
      word.length == 1
          ? word[0].toUpperCase()
          : '${word[0].toUpperCase()}${word.substring(1)}'
  ];
  return words.join(' ');
}