toTitleCase method

String toTitleCase()

Converts the string into title case.

Implementation

String toTitleCase() {
  final value = orEmpty().trim();
  if (value.isEmpty) {
    return '';
  }

  return value.split(RegExp(r'\s+')).map((word) {
    if (word.isEmpty) {
      return word;
    }
    return '${word[0].toUpperCase()}${word.substring(1).toLowerCase()}';
  }).join(' ');
}