toTitleCase property

String get toTitleCase

Converts string to Title Case (e.g. "hello world" -> "Hello World").

Implementation

String get toTitleCase {
  if (isBlank) return '';
  return trim()
      .split(RegExp(r'\s+'))
      .map(
        (word) =>
            word.isEmpty
                ? ''
                : word[0].toUpperCase() + word.substring(1).toLowerCase(),
      )
      .join(' ');
}