capitalizeFirstLetterOfEveryWord function

String capitalizeFirstLetterOfEveryWord(
  1. String text
)

Utility function to capitalize the first letter of every word

Implementation

String capitalizeFirstLetterOfEveryWord(String text) {
  List<String> words = text.split(' ');
  List<String> capitalizedWords = [];

  for (String word in words) {
    if (word.isNotEmpty) {
      String capitalizedWord =
          word[0].toUpperCase() + word.substring(1).toLowerCase();
      capitalizedWords.add(capitalizedWord);
    }
  }

  return capitalizedWords.join(' ');
}