capitalizeWords static method

String capitalizeWords(
  1. String text
)

Capitalizes the first letter of each word in a String and returns the result.

Example:

String str = "hello world";
String capitalized = StringUtils.capitalizeWords(str);
print(capitalized); // Hello World

Implementation

static String capitalizeWords(String text) {
  return text.isNotEmpty
      ? text
          .split(' ')
          .map((word) => word[0].toUpperCase() + word.substring(1))
          .join(' ')
      : text;
}