capitalizeWords function

String capitalizeWords(
  1. String input
)

Implementation

String capitalizeWords(String input) {
  if (input.isEmpty) return "";

  // Split the input string into words
  List<String> words = input.split(' ');

  // Capitalize the first letter of each word and handle "id"
  return words.map((word) {
    if (word.toLowerCase() == 'id') {
      return 'ID'; // Capitalize "id" as "ID"
    }
    if (word.isEmpty) return '';
    return word[0].toUpperCase() + word.substring(1).toLowerCase();
  }).join(' ');
}