title method

String title()

Title case: capitalizes each word separated by whitespace.

Implementation

String title() {
  if (isEmpty) return this;
  final parts = trim().split(RegExp(r'\s+'));
  return parts
      .map(
        (w) =>
            w.isEmpty ? w : w[0].toUpperCase() + w.substring(1).toLowerCase(),
      )
      .join(' ');
}