Is any update for this question Flutter TextField value always uppercase & debounce ?
I’ve already tried some of the code to make the input text become uppercase.
class UpperCaseTextFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
return TextEditingValue(
text: newValue.text.toUpperCase(),
selection: newValue.selection,
);
}
}
class UpperCaseTextFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
return newValue.copyWith(text: newValue.text.toUpperCase());
}
}
But it works not correct when I type "QWER", it will always become "QQWQWEQWER"
Here is the video : https://drive.google.com/file/d/1q3dwuVMPzt_kBP4c2lyiahQ6znkSbM-n/view?usp=sharing
I prefer not to use textCapitalization
because the user still can change it to lowercase, if the formatter dosen’t work.
Use TextInputFormatter to make textfield input become uppercase
2
Answers
You can use TextEditingController to make user input always UPPERCASE, With the below code the user can’t change it to lowercase.
This will work Happy Coding!
Assign a controller to TextField.
Convert the text value in controller toUpperCase() in onChanged function.