capitalizeFirstLetterFormatter static method
capitalizeFirstLetterFormatter capitalizes the first letter of each word.
Implementation
static List<TextInputFormatter> capitalizeFirstLetterFormatter() {
return [
TextInputFormatter.withFunction((oldValue, newValue) {
if (newValue.text.isEmpty) {
return newValue;
}
final List<String> words = newValue.text.split(' ');
final List<String> capitalizedWords = words.map((word) {
if (word.isEmpty) {
return '';
}
return word[0].toUpperCase() + word.substring(1);
}).toList();
return newValue.copyWith(text: capitalizedWords.join(' '));
}),
];
}