title method

String title()

Returns a String where first character of every words is converted to upperCase.

print('this123'.title()); // 'This123'
print('This is title'.title()); // 'This Is Title'
print('tHiS iS tiTle'.title()); // 'This Is Title'

Implementation

String title() {
  final List<String> words = split(' ');

  if (contains(' ')) {
    words.setAll(0, words.map((element) => element.capitalize()));
    return words.join(' ');
  } else {
    return capitalize();
  }
}