formatEditUpdate method
Called when text is being typed or cut/copy/pasted in the EditableText.
You can override the resulting text based on the previous text value and the incoming new text value.
When formatters are chained, oldValue
reflects the initial value of
TextEditingValue at the beginning of the chain.
Implementation
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
final length = newValue.text.length;
if (length == 1 ||
(newValue.text.length > 1 && newValue.text[length - 2] == ' ')) {
//находим символ по индексу
final oldChar = newValue.text[length - 1];
// капитализируем символ
final newChar = oldChar.toUpperCase();
// замена символа на заглавный
final newText = replaceCharAt(newValue.text, length - 1, newChar);
return TextEditingValue(
text: newText,
selection: newValue.selection,
);
} else {
return TextEditingValue(
text: newValue.text,
selection: newValue.selection,
);
}
}