capitalizeEachWord method
This function returns given string with each word capital
Implementation
String capitalizeEachWord() {
if (validate().isEmpty) {
return '';
}
final capitalizedWords = this!.split(' ').map((word) {
if (word.isEmpty) {
return word;
}
final firstLetter = word[0].toUpperCase();
final remainingLetters = word.substring(1).toLowerCase();
return '$firstLetter$remainingLetters';
});
return capitalizedWords.join(' ');
}