toTitleCase property

String get toTitleCase

Converts the string to title case (first letter of each word capitalized, rest lowercase).

Implementation

String get toTitleCase => split(' ')
    .map(
      (String word) => word.isNotEmpty
          ? word[0].toUpperCase() + word.substring(1).toLowerCase()
          : '',
    )
    .join(' ');